gpt4 book ai didi

Javascript 元素总和值

转载 作者:行者123 更新时间:2023-11-28 16:16:37 24 4
gpt4 key购买 nike

JavaScript 代码:

function getCheckbox(name,id){
var check = 0;
var deger = "option-checkbox-"+id;
var dom = document.getElementById(deger);
if( dom.checked )
check += parseFloat( dom.value );
else check -= parseFloat( dom.value );
return check.toFixed(2);**//right value.(12.45)**
}

function getRadio(name,id) {
var radio=0;
var deger="option-radio-"+id;
var radio="option["+name+"]";
var selectedli = document.getElementsByName(radio);
var degerli = document.getElementById(deger);
if( selectedli.checked )
radio = parseFloat( degerli.value );
else radio = parseFloat( degerli.value )
return radio.toFixed(2)**//right value.(42.00)**
}

function getSelected(name,id) {
var selectedid="option["+name+"]";
var selecte = 0;
var selected = document.getElementById( selectedid );
selecte = parseFloat(selected.value);
return selecte.toFixed(2);**//right value.(-12.29)**
}

function toplam(name,id) {**//not expected(0)**
var toplan = 0;
toplan = getSelected(name,id)+getRadio(name,id)+getCheckbox(name,id);
$( '#toplam_goster' ).fadeOut(200, function(){
document.getElementById("toplam_goster").innerHTML = toplan;
});
$( '#toplam_goster' ).fadeIn(200);
}

.在最后一个函数中返回0。我该如何修复它。

谢谢。

最佳答案

return selecte.toFixed(2); // this returns string and addition might return 0

要么返回数字,即返回selecte*1或在添加之前转换为数字,即

toplan=getSelected(name,id)*1+getRadio(name,id)*1+getCheckbox(name,id)*1; 

关于Javascript 元素总和值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11291961/

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