gpt4 book ai didi

jquery 将数字视为字符串

转载 作者:行者123 更新时间:2023-12-01 07:19:04 25 4
gpt4 key购买 nike

这是我想要计算的jsfiddle。我不知道如何将这些字符串转换为整数。 http://jsfiddle.net/Ygsrv/2/

这是代码:

$('#get').click(function(){
var priceProduct = 18.9
var length = $("#awp_group_5 option:selected").text().replace(/cm$/, '');
var width = $("#awp_group_4 option:selected").text().replace(/cm$/, '');
var priceProduct2 = priceProduct + (width + length * 30 );
alert(priceProduct2);

});

最佳答案

您应该使用parseInt(yourStringHere);

您应该执行以下操作

var priceProduct2 = priceProduct + (parseInt(width) + parseInt(length) * 30 );

查看这个例子:fiddle http://jsfiddle.net/mayooresan/Ygsrv/3/

关于jquery 将数字视为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15804326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com