日期:2014-05-16  浏览次数:20362 次

如何用循环给表单内每个checkbox加个事件
<html>

<head>

<title> </title>

</head>

<body>
<span   class= "STYLE1 ">   欢迎订阅时事通讯: </span> <br   />
<br   />
请选择您要订阅的时事通讯: <br   />
<form   id= "form1 "   name= "form1 "   method= "post "   action= " ">
    <label>
    <input   type= "checkbox "   name= "C "   value= "C "   />
    C </label>
    <br   />
    <label>
    <input   type= "checkbox "   name= "C++ "   value= "C++ "   />
    C++ </label>
    <br   />
    <label>
    <input   type= "checkbox "   name= "C# "   value= "C# "   />
    C# </label>
    <br   />
    <label>
    <input   type= "checkbox "   name= "JAVA "   value= "JAVA "   />
    JAVA </label>
    <br   />
    <label>
    <input   type= "checkbox "   name= "VB "   value= "Visual   Basic "   />
    Visual   Basic </label>
    <br   />
    <label>
    <input   type= "checkbox "   name= "ORC "   value= "Oracle "   />
    Oracle </label>
    <br   />
    <label>
    <input   type= "checkbox "   name= "SQL "   value= "Sql   Server "   />
    SQL   Server </label>
    <br   />
    <label>
    <input   type= "text "   name= "textfield "   />
    </label>
    <br   />
    <br   />

</form>
<script   language= "javascript "   type= "text/javascript ">
       
for   (var   i=0;form1.checkbox.length;i++)   {   //这里取表单中checkbox个数应该有问题
    if   (checkbox[i].type= "checkbox "){
            checkbox[i].onclick=function()     {  
                if(this.checked==true){
                    form1.textfield.value= "你选中了 "+form1.checbox[i].value+ "语言选项。 ";
                }   else   {
                    form1.textfield.value= "你取消了 "+form1.checbox[i].value+ "语言选项。 ";
                }
            }        
    }

}
</script>

</body&