-3

Hi i am trying to work out the total price in jquery

I have try

full jquery

This is my jquery for changing the price in get_price i have a select statement an I am echoing the price echo $row2['Price'];

The way this works is that when every you change the length the price will change

so in pricetag you will get for an example 40.00 without the £

4

1 回答 1

1

” “你需要在执行前#pricetag will be somelike like £40.00去掉£in 。像这样的东西:#pricetagparseInt()

var price = '\u00A3' + (parseInt($('#pricetag').text().replace(/\u00A3/, ''), 10) * qty);

parseInt()从字符串的开头开始搜索数字,并在找到的第一个非数字处停止搜索。在您的情况下,第一个字符是£,所以parseFloat()返回NaN,它NaN在与 一起使用时产生*


编辑

无论您在 中的数字前面有什么(或没有任何东西)#pricetag,您都可以使用它来删除它:

var price = '\u00A3' + parseInt($('#pricetag').text().replace(/^\D/, ''), 10) * qty;

另请注意,您必须在计算中使用它qty 之前进行验证。

jsFiddle 的现场演示

于 2013-07-21T19:45:49.277 回答