其实你想要知道的是怎么动态的求值,那么有一个JavaScript的函数Eval你就不能不知道,给你一个简单的例子:
function countSum()
{
var nRow = 2;
var nCol = 3;
for (var i = 1; i <= nRow; i++)
{
var nSum = 0;
for (var j = 1; j <= nCol; j++)
{
var strTextName = "document.forms[0].col" + j + "_" + i;
var nNum = eval(strTextName + ".value");
nSum = nSum + nNum;
}
alert(nSum);
}
}
Good night.
function countSum()
{
var nRow = 2;
var nCol = 3;
for (var i = 1; i <= nRow; i++)
{
var nSum = 0;
for (var j = 1; j <= nCol; j++)
{
var strTextName = "document.forms[0].col" + j + "_" + i;
var nNum = eval(strTextName + ".value");
nSum = nSum + nNum;
}
alert(nSum);
}
}
Good night.