0
對不起,如果我問到與以前類似的事情,但我已經嘗試過,並在編碼javascipt時感到困惑。 和以前一樣,我想用只有NaN的條件= 0的條件來計算Grand總數,如果不是NaN = Total。當我嘗試條件isNaN它是正確的,但如果不是NaN,他總是= 0爲什麼?我已經嘗試onKeyup,onBlur,並onChange也許我有錯誤的功能?可以幫助我嗎?如何計算列的總和只是條件的內容?
<html>
<head>
<form method = "POST" action="text.php" name="form">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/jquery-ui.css"/>
<script src="js/jquery-1.9.1.js"></script>
<script src="js/jquery-ui.js"></script>
<!--<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>-->
<script type="text/javascript">
function cal1() {
var a = parseInt($(".qty1").val());
var b = parseInt($(".price1").val());
var c1 = a * b; //a * b
$(".total1").val(c1);
grandtotal();
}
function cal2() {
var a = parseInt($(".qty2").val());
var b = parseInt($(".price2").val());
var c2 = a * b; //a * b
$(".total2").val(c2);
grandtotal();
}
function cal3() {
var a = parseInt($(".qty3").val());
var b = parseInt($(".price3").val());
var c3 = a * b; //a * b
$(".total3").val(c3);
grandtotal();
}
function grandtotal() {
var a1 = parseInt($(".total1").val());
var b1 = parseInt($(".total2").val());
var c1 = parseInt($(".total3").val());
if (isNaN(a1.value) == true)
{
var a1=0;
}
else
{
var a1 = parseInt($(".total1").val());
}
if (isNaN(b1.value) == true)
{
var b1=0;
}
else
{
var b1 = parseInt($(".total2").val());
}
if (isNaN(c1.value) == true)
{
var c1=0;
}
else
{
var c1 = parseInt($(".total3").val());
}
var z = a1+b1+c1; // a1+b1+c1
$(".grandtotal").val(z);
}
</script>
</head>
<body>
<table border="1">
<tr>
<td>
<table height="51" border="0" cellspacing="2">
<tr>
<td>
<div align="center">Price</div>
</td>
<td>
<div align="center"> Total Price</div>
</td>
</tr>
<tr>
<td>
<input class="qty1" type="text" name="qty1" onblur="qty_blur(this);" onkeyup="cal1();" value="">
</td>
<td>
<input class="price1" type="text" name="price1" onblur="price_blur(this);" onkeyup="cal1();" value="">
</td>
<td>
<input class="total1" type="text" name="total1" value="0" readonly=true onkeyup="grandtotal();">
</td>
</tr>
<tr>
<td>
<input class="qty2" type="text" name="qty2" onblur="qty_blur(this);" onkeyup="cal2();" value="">
</td>
<td>
<input class="price2" type="text" name="price2" onblur="price_blur(this);" onkeyup="cal2();" value="">
</td>
<td>
<input class="total2" type="text" name="total2" value="0" readonly=true onkeyup="grandtotal();">
</td>
</tr>
<tr>
<td>
<input class="qty3" type="text" name="qty3" onblur="qty_blur(this);" onkeyup="cal3();" value="">
</td>
<td>
<input class="price3" type="text" name="price3" onblur="price_blur(this);" onkeyup="cal3();" value="">
</td>
<td>
<input class="total3" type="text" name="total3" value="0" readonly=true onkeyup="grandtotal();">
</td>
</tr>
</table>
</td>
</tr>
</table>
<table>
<tr div class="grandtotal">
<td>
Grand Total :
</td>
<td>
<input class="grandtotal" name="grandtotal" type="text" readonly=true value="">
</td>
</tr>
</div>
</table>
</body>
哦,你妳對Thx很多你的評論哈哈 – Vilthering 2014-10-12 09:35:22