字符串加变量的问题
以下是代码:
要实现,当点按钮4时,按钮1,2,3都不可用。
check()传递字符串‘a,b,c’对应的按钮是1,2,3
下面的代码测试了不提示出错,但就是不能实现所需的功能。
<script language=javascript>
function check(words){
var ss,tt;
ss = words.split( ", ");
for (i=0;i <ss.length;i++){
tt=document.getElementsByName(ss[i]);
tt.disabled=true;
}
}
</script>
<form method= "POST " action= " " name= "form1 ">
<p> <input type= "button " value= "1 " name= "a "> <input type= "button " value= "2 " name= "b "> <input type= "button " value= "3 " name= "c "> <input type= "button " value= "4 " name= "btn4 " onclick= "check( 'a,b,c '); "> </p>
</form>
大家来帮我找找原因。谢谢了!
------解决方案--------------------tt.disabled=true;改成tt[0].disabled=true;
------解决方案--------------------tt[0].disabled=true;即可