在使用循环动态读取/分配值给文本输入时,我遇到了这个问题。
这是它的声明方式:
if ( $myrow[9] > 0 )
{ $dsl_ctr=$dsl_ctr+1;
print "<input type='hidden' name='old_dsl_cost_".$dsl_ctr."' value='".$myrow[9]."'>";
print "<td align='right'> ".number_format($myrow[9],3,'.',',')." </td>".
"<td align='right'><input type='text' size='5' name='new_dsl_cost_".$dsl_ctr."'> </td>";
}
说我有以下输入文本:
old_dsl_cost_1 new_dsl_cost_1
old_dsl_cost_2 new_dsl_cost_2
old_dsl_cost_3 new_dsl_cost_3
使用此语句访问它时出错:
for (ctr=1;ctr<=max;ctr++)
{
document.a.new_dsl_cost_['ctr'].value = eval(document.a.old_dsl_cost_['ctr'].value) +
eval(document.a.dsl_cost.value);
}
循环中的以上语句应为:
document.a.new_dsl_cost_1.value = eval(document.a.old_dsl_cost_1.value) +
eval(document.a.dsl_cost.value);
我需要循环和计数器,因为数字不确定。
Google暂时没有太多帮助:(