利用javascritp 求和。却得不到结果。。。 要用parseInt转换一下数据类型 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 theall+=parseint(document.getElementById("zj"+i).value);这样写么?还是一样啊。。得不到效果 要求得多个框中别人输入的值的总合。//统一把input的name 属性明名为(name='pricename')var allprice = document.getElementsByName('pricename');//为一数组按数组操作获得所有input框输入数据的一个数组剩下的就好办了 如果把NAME值写成一样的话,那提交的时候不是不能取值了? theall=0;allprice=document.getElementById("hj").value; //下一行的NUM是求和的总个数。。for(i=1;i <=num;i++){theall+=document.getElementById("zj"+i).value;theall=theall; // 我想知道 ,你这句话是什么意思 ?你自己知道是什么意思不 ?alert(theall);}allprice=theall;//这里是把结果赋给下一个框中 【这就是付给input值么?搞清楚好不好,allprice是个变量,不是对象也不是对象的属性,而是对象的属性值!】========这个社会都做了什么? ==================>>>>>>>>>theall=0;for(i=1;i <=num;i++){theall+=document.getElementById("zj"+i).value;}document.getElementById("hj").value=theall; 写详细点把//统一把input的name 属性明名为(name='pricename') function sumprice(){var allprice = document.getElementsByName('pricename');//为一数组按数组操作 var sum =0; for(var i =0;i<allprice.length;i++){ sum = sum + parseInt(allprice[i].value); } alert(sum);}//html <input type="text" name="pricename" /> <input type="text" name="pricename" /> <input type="button" value="testtr" onclick="sumprice()" /> 可以写几个 <input type="hidden" name="" id=""/>再用js控制下不就行了 可以不用这个parseInt 建议用这个吧Number不然的话。可能得不到你想要的结果 theall=0; allprice=document.getElementById("hj").value; //下一行的NUM是求和的总个数。。 for(i=1;i <=num;i++){ theall+=Number(document.getElementById("zj"+i).value); theall=theall; alert(theall); } document.getElementById("hj").value=theall; //这里是把结果赋给下一个框中 // 结果赋给下一个框好像这样了document.getElementById("hj").value=theall; 如何实现用JS无刷新切换页面风格? jquery tabs 一个站点下多次使用问题 CHROME 子窗口 无法返回值 Extjs :怎么动态调用js文件 javascript 可以弹出类似confirm那样不过有3个选项的弹出框吗 请问下这段代码该如何修改才正确 如何得到execCommand('createBookmark',false,'Anchor')方法后的锚点值? 如何做这样的下拉菜单 怎么样用最简单的脚本控制div层的显示隐含! ActiveX 的 calendar 问题 FireFox 真让人头疼,怎么获取这个对象? 能帮我解释下以下地方吗?谢谢大家老!!
//统一把input的name 属性明名为(name='pricename')
var allprice = document.getElementsByName('pricename');//为一数组按数组操作获得所有input框输入数据的一个数组剩下的就好办了
allprice=document.getElementById("hj").value; //下一行的NUM是求和的总个数。。
for(i=1;i <=num;i++){
theall+=document.getElementById("zj"+i).value;
theall=theall; // 我想知道 ,你这句话是什么意思 ?你自己知道是什么意思不 ?
alert(theall);
}
allprice=theall;//这里是把结果赋给下一个框中 【这就是付给input值么?搞清楚好不好,allprice是个变量,不是对象也不是对象的属性,而是对象的属性值!】
========这个社会都做了什么? ==================>>>>>>>>>theall=0;
for(i=1;i <=num;i++){
theall+=document.getElementById("zj"+i).value;
}
document.getElementById("hj").value=theall;
//统一把input的name 属性明名为(name='pricename')
function sumprice(){
var allprice = document.getElementsByName('pricename');//为一数组按数组操作
var sum =0;
for(var i =0;i<allprice.length;i++){
sum = sum + parseInt(allprice[i].value);
} alert(sum);
}//html
<input type="text" name="pricename" />
<input type="text" name="pricename" />
<input type="button" value="testtr" onclick="sumprice()" />
<input type="hidden" name="" id=""/>
再用js控制下不就行了
parseInt
建议用这个吧Number
不然的话。可能得不到你想要的结果
allprice=document.getElementById("hj").value; //下一行的NUM是求和的总个数。。
for(i=1;i <=num;i++){
theall+=Number(document.getElementById("zj"+i).value);
theall=theall;
alert(theall);
}
document.getElementById("hj").value=theall; //这里是把结果赋给下一个框中
document.getElementById("hj").value=theall;