<input onclick="f1(this);" type=checkbox name='test' id='1'>
<input onclick="f1(this);" type=checkbox name='test' id='2'>
<input onclick="f1(this);" type=checkbox name='test' id='3'>

解决方案 »

  1.   

    <input onclick="f1(this);" type=checkbox name='test' id='ck1'>
    <input onclick="f1(this);" type=checkbox name='test' id='ck2'>
    <input onclick="f1(this);" type=checkbox name='test' id='ck3'>
    <script>
    function f1(obj)
    {  var ckobj=document.g e t E l e m e n t s B y N a m e("test");//去掉空格再运行
      for(var i=0;i<3;i++)
      {
      
      if(ckobj[i].id==obj.id)  { ckobj[i].checked=true; }  else  {   ckobj[i].disabled=true;  }
        
      }
    }
    </script>
      

  2.   

    这样也可以,呵呵:
    <SCRIPT language='Jscript'>
    function f1(obj){
      for(var i=0;i<document.all.test.length;i++){
         if(document.all.test[i].id == obj.id){
            obj.checked = true;
         }else{
            document.all.test[i].checked = false;
         }
      }
    }
    </SCRIPT>
    <input onclick="f1(this);" type=checkbox name='test' id='1'>
    <input onclick="f1(this);" type=checkbox name='test' id='2'>
    <input onclick="f1(this);" type=checkbox name='test' id='3'>
      

  3.   

    以上方法需要确定id的唯一性,支持任意多个checkbox。
      

  4.   

    既然传入了点击的对象,就没有必要使用id了function f1(obj){
      o = document.all[obj.name];
      for(var i=0;i<o.length;i++){
         if(o[i] == obj){
            obj.checked = true;
         }else{
            o[i].checked = false;
         }
      }
    }
    这样就不受id唯一性限制了
    也不需要预先知道checkbox的名字,支持任意组  o = document.all[obj.name];
    写做
      o = document.formname[obj.name];
    就更通用了,因为all属性只在ie兼容浏览器可用
      

  5.   

    <input onclick="f1(this);" type=checkbox name='test'>
    <input onclick="f1(this);" type=checkbox name='test'>
    <input onclick="f1(this);" type=checkbox name='test'>function f1(cbx){
        var cbxs = docuemnt.g e t E l e m e n t s B y N a m e (cbx.name);
        for(var i=0;i<cbxs.length;i++){
            if(cbxs[i]!=cbx){
               cbxs[i].checked=false;
            }
        }
        cbx.checked=true;//加不加此句,看是否允许出现“所有都不选”的情况
    }
      

  6.   

    熟悉web2.0,blog,ajax,rss,.net2005等请进入
    http://blog.csdn.net/datehr/category/198305.aspx