JQuery:计算插件不计算总价
:插件 主页:链接。
:javascript
$("[id^=total_price_ht]").calc(
// the equation to use for the calculation
"qty * price",
{
qty: $("[id^=unit_quantity_]"),
price: $("[id^=unit_price_ht_]")
},
function (s){
// return the number as a dollar amount
return "$" + s.toFixed(2);
}
);
:html
<tr id="lines[0]">
<td>
<input id="0" type="checkbox" class="hiddenCheckbox">
<label for="0" class="prettyCheckbox checkbox list"><span class="holderWrap" style="width: 18px; height: 19px; "><span class="holder" style="width: 18px; "></span></span></label>
</td>
<td>
<input class="required" name="lines[0][title]" placeholder="Title" type="text">
</td>
<td>
<input name="lines[0][description]" placeholder="Description" type="text">
</td>
<td>
<input class="required" id="unit_quantity_0" name="lines[0][quantity]" placeholder="Quantité" type="text" value="0,00">
</td>
<td>
<input class="required" id="unit_price_ht_0" name="lines[0][unit_price_ht]" placeholder="Prix unit. HT" type="text" value="0,00">
</td>
<td class="price" id="total_price_ht_0">$0.00</td>
</tr>
页面加载后,我可以在total_price_ht字段中看到“$0.00”,但当我更改数量或价格时,它的值不会改变。
我做错了什么吗?
:plugin
Homepage: Link.
:javascript
$("[id^=total_price_ht]").calc(
// the equation to use for the calculation
"qty * price",
{
qty: $("[id^=unit_quantity_]"),
price: $("[id^=unit_price_ht_]")
},
function (s){
// return the number as a dollar amount
return "$" + s.toFixed(2);
}
);
:html
<tr id="lines[0]">
<td>
<input id="0" type="checkbox" class="hiddenCheckbox">
<label for="0" class="prettyCheckbox checkbox list"><span class="holderWrap" style="width: 18px; height: 19px; "><span class="holder" style="width: 18px; "></span></span></label>
</td>
<td>
<input class="required" name="lines[0][title]" placeholder="Title" type="text">
</td>
<td>
<input name="lines[0][description]" placeholder="Description" type="text">
</td>
<td>
<input class="required" id="unit_quantity_0" name="lines[0][quantity]" placeholder="Quantité" type="text" value="0,00">
</td>
<td>
<input class="required" id="unit_price_ht_0" name="lines[0][unit_price_ht]" placeholder="Prix unit. HT" type="text" value="0,00">
</td>
<td class="price" id="total_price_ht_0">$0.00</td>
</tr>
Once the page loads, I can see '$0.00" in the total_price_ht field but it's value doesn't get changed when I change the quantity or the price.
What am I doing wrong? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为每次要重新计算总计时都需要调用
calc
插件:示例: http://jsfiddle.net/upEZW/
I think you need to call the
calc
plugin every time you want to recalculate the total:Example: http://jsfiddle.net/upEZW/