我试图运行JavaScript环以下,但它不工作:无法调用Javascript方法
function column_total()
{
alert("In column_total method");
var row1val=0,row2val=0,row3val=0,row4val=0,row5val=7,row6val=0,row7val=0,row8val=0,row9val=0,row10val=0,row11val=0,row12val=0;
for(i=1;i<=12;i++)
{
for(j=i;j<=i;j++)
{
alert("In j loop");
row"+j+"val += parseFloat(document.getElementById('p'"+i+").value);
row"+j+"val += parseFloat(document.getElementById('d'"+i+").value);
row"+j+"val += parseFloat(document.getElementById('o'"+i").value);
document.getElementById('t1').value=row"+i+"val;
}
var rowtotalval=row1val+row2val+row3val+row4val+row5val+row6val+row7val+row8val+row9val+row10val+row11val+row12val;
return true;
}
}
在我打电话通过文本框T1的onfocus
属性的代码,这里的HTML是html代码:
<input type="text" name="p1" id="p1"></input>
<input type="text" name="p2" id="p2"></input>
<input type="text" name="d1" id="d1" ></input>
<input type="text" name="d2" id="d2" ></input>
<input type="text" name="o1" id="o1" ></input>
<input type="text" name="o2" id="o2" ></input>
<input type="text" name="t1" id="t1" onfocus="column_total()"></input>
'for(j = i; j <= i; j ++)' – fcalderan
什么?你有很多错误,你想要做什么? – Alexis
除了语法错误之外,你的函数在外层循环的第一次迭代中返回true ......并不完全确定你实际要完成的工作。 – arthurakay