日期:2014-05-16  浏览次数:20373 次

JScript数组加法请教
有几个input数组表单
<input   name= "fee1[] "> <input   name= "fee2[] "> <input   name= "fee[] ">
<input   name= "fee1[] "> <input   name= "fee2[] "> <input   name= "fee[] ">
实现的效果是fee[]动态输出fee1[]+fee2[]的值,不知道如何用javascript,大家帮帮忙,偶想了几天了。

------解决方案--------------------
为什么要这么设计呢?
有点怪
function foo()
{
var a = document.getElementsByName( 'fee[] ');
var b = document.getElementsByName( 'fee1[] ');
var c = document.getElementsByName( 'fee2[] ');
var d ;
var e ;
for(var i=0;i <a.length;i++)
{
d = parseInt(b[i].value) ? parseInt(b[i].value) : ' ';
e = parseInt(c[i].value) ? parseInt(c[i].value) : ' ';
a[i].value = d+e;
}
}
<input name= "fee1[] "> <input name= "fee2[] "> <input name= "fee[] " onClick= "foo() ">
<input name= "fee1[] "> <input name= "fee2[] "> <input name= "fee[] " onClick= "foo() ">