jQuery 计算不起作用
我在使用 jquery 计算插件时遇到问题。我一直在不断地尝试,由于我缺乏javascript知识,这已经相当困难了。
这是我的代码:
<!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>
我做错了什么?
I am having a problem making the jquery calculation plugin to work. I have been trying endlessly, and due to my lack of javascript knowledge, it has been quite difficult.
Here is my code:
<!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>
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,也许从包含 jQuery 开始?
没有 jQuery 就无法使用 jQuery :))
然后你还需要包含计算插件(将其复制到你的文件夹,不要热链接!)
最后你的脚本:
你丢失了:
Hmmm maybe start from including jQuery?
You can't use jQuery without jQuery :))
Then you need to include calculation plugin as well (copy it to your folder, don't hotlink!)
At last your script:
you was missing:
首先你需要阅读jquery的文档以及如何在网页中使用。
您需要调用 jquery 库,如下所示(在
末尾或在
中):
然后您需要调用jquery.calc 插件(不要忘记先下载!! !)。最后你必须得到这样的东西(在
的末尾或在
中):
然后才调用你的:
First you need to read the documentation of jquery and how to use in a web page.
You need to call the jquery library, something like this (at the end of your
<body>
or in the<head>
):Then you need to call the jquery.calc plugin (don't forget downloading first!!!). Finally you has to get something like this (at the end of your
<body>
or in the<head>
):And only then call your: