我有一个问题,使jquery计算插件的工作。我一直在无休止地尝试,并且由于缺乏JavaScript知识,这一直非常困难。jQuery计算不起作用
这里是我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<table width="500">
<col style="width: 50px;" />
<col />
<col style="width: 60px;" />
<col style="width: 110px;" />
<tr>
<th>
Qty
</th>
<th align="left">
Product
</th>
<th>
Price
</th>
<th>
Total
</th>
</tr>
<tr>
<td align="center">
<input type="text" name="qty_item_1" id="qty_item_1" value="1" size="2" />
</td>
<td>
Bottle 1
</td>
<td align="center" id="price_item_1">
£29.00
</td>
<td align="center" id="total_item_1">
£29.00
</td>
</tr>
<tr>
<td align="center">
<input type="text" name="qty_item_2" id="qty_item_2" value="1" size="2" />
</td>
<td>
Bottle 2
</td>
<td align="center" id="price_item_2">
£60.00
</td>
<td align="center" id="total_item_2">
£60.00
</td>
</tr>
<tr>
<td colspan="3" align="right">
<strong>Grand Total:</strong>
</td>
<td align="center" id="grandTotal">
</td>
</tr>
</table>
<script type="text/javascript">
$("input[name^=qty_item_]").bind("keyup", recalc);
$("[id^=total_item]").calc(
"qty * price",
{
qty: $("input[name^=qty_item_]"),
price: $("[id^=price_item_]")
},
function (s){
return "£" + s.toFixed(2);
},
function ($this){
var sum = $this.sum();
$("#grandTotal").text(
"£" + sum.toFixed(2)
);
}
);
</script>
</body>
</html>
我在做什么错?
当你输入密码,不要把它在'输入代码在这里'块之后,把它放在那里。 – Brandon