天天看點

checkbox做成可以單選取消

checkbox做成可以單選取消

<html>  

  <head><title>mars test page</title></head>  

  <script>  

  function chk(obj)  

  {  

       var boxarray = document.getelementsbyname('c1');  

       for(var i=0;i<=boxarray.length-1;i++){  

            if(boxarray[i]==obj && obj.checked){  

               boxarray[i].checked = true;  

            }else{  

               boxarray[i].checked = false;  

            }  

       }   

  }  

 </script>  

  <body>  

  <form name="form1">  

    <input type="checkbox" name="c1" value="1" onclick="return chk(this);">a  

    <input type="checkbox" name="c1" value="2" onclick="return chk(this);">b  

    <input type="checkbox" name="c1" value="3" onclick="return chk(this);">c  

  </form>  

  </body>  

</html>  

上一篇: jquery選中
下一篇: 日期控件

繼續閱讀