我正在尝试在提交表单时更改div的数字内容,并在:submit上使用以下jQuery,但是我不确定第二部分是否为变量使用了正确的语法,因为它不起作用。
// gets the contents of the selected option, and strips everything before the "$" and all non-numeric characters save the decimal
var changingprice = $('#mydiv .cartbutton form :selected')
.text()
.split('$')
.pop()
.replace(/[^\d.]/g, '');
// jQuery to update the content of the #cart-price-counter div.
$('#cart-price-counter')
.html(function(i, val) {
return (val*1+changingprice).toFixed(2);
});
尝试使用parseInt
或parseFloat
表示changingprice
喜欢,
$('#cart-price-counter')
.html(function(i, val) {
return (val*1+parseFloat(changingprice)).toFixed(2);
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句