JS赋值问题
function addinput(c){
var sess0 = "q ";
var sess1 = "w ";
var sess2 = "e ";
for (var m=0;m <c;m++ )
{
document.getElementById( "strfile "+m+ " ").value=sess+m;
}
}
上面的C是外部传入的参数,
比如外面有3个input
现在传入参数 让 c=3
<input name= "strfile0 " type= "text " />
<input name= "strfile1 " type= "text " />
<input name= "strfile2 " type= "text " />
如何让JS给上面三个文本框赋值呢?
document.getElementById( "strfile "+m+ " ").value=sess+m;
这句是错的,希望高人能指点下
------解决方案--------------------document.getElementById( "strfile "+m+ " ").value = eval( "sess "+m);
------解决方案-------------------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME= "Generator " CONTENT= "EditPlus ">
<META NAME= "Author " CONTENT= " ">
<META NAME= "Keywords " CONTENT= " ">
<META NAME= "Description " CONTENT= " ">
</HEAD>
<BODY>
<FORM METHOD=POST ACTION= " ">
<input name= "strfile0 " type= "text " />
<input name= "strfile1 " type= "text " />
<input name= "strfile2 " type= "text " />
</ <FORM METHOD=POST ACTION= " ">
<SCRIPT>
function addinput(c){
var sess0 = "q ";
var sess1 = "w ";
var sess2 = "e ";
for (var m=0;m <c;m++ )
{
document.all( "strfile "+m).value= "sess "+m;
//alert(document.all.tags( "input "));
}
}
addinput( "3 ");
</SCRIPT>
</FORM>
</BODY>
</HTML>
------解决方案--------------------document.getElementById( "strfile "+m+ " ").value = eval( "sess "+m);