xiaobojava 发表于 2013-2-7 16:17:21

两个radio或checkbox名称不同现实只能选择一个

 
//**********************radio
<!--
  window.onload = function(){
   var inputs = document.getElementsByTagName("INPUT");
    for(var e in inputs){
        if(inputs.type == "radio"){
            inputs.onclick = function(){
                for(var e in inputs){
                //两种写法都可以,第一种采用的是正则表达式,效率相对第二种较底,但是未改变HTML标准比第二种容//易理解
                    //if(inputs.type == "radio" && this.name.replace(/\d+/g,"") === //inputs.name.replace(/\d+/g,""))
                    if(inputs.type == "radio" && this.group === inputs.group)
                      inputs.checked = false;
                }
                this.checked = true;
            };

        }
    }
  }
 
<form>
<input type="radio" name="a0" group="a"/>a0<input type="radio" name="a1" group="a">a1
 
<br/>

<input type="radio" name="b0"/>b0<input type="radio" name="b1">b1

</form>
 
两个radio的名称可以不同,但前名的字前面的要一样,后面的数字不一样
 
 
//******************Checkbox
 
 
 window.onload = function(){
   var inputs = document.getElementsByTagName("INPUT");
    for(var e in inputs){
        if(inputs.type == "checkbox"){
            inputs.onclick = function(){
                for(var e in inputs){
                //两种写法都可以,第一种采用的是正则表达式,效率相对第二种较底,但是未改变HTML标准比第二种容//易理解,第二种兼容性不好
                    if(inputs.type == "checkbox" && this.name.replace(/\d+/g,"") === inputs.name.replace(/\d+/g,""))
                    //if(inputs.type == "checkbox" && this.group === inputs.group)
                      inputs.checked = false;
                }
                this.checked = true;
            };

        }
    }
  }
<form>
        <input  type="checkbox" name="RPT_ROAD_A2__APPROVAL_PASS_1" />aaa
        <input  type="checkbox" name="RPT_ROAD_A2__APPROVAL_PASS_2" />bbb
</form>
 
两个checkbox的名称可以不同,但前名的字前面的要一样,后面的数字不一样
页: [1]
查看完整版本: 两个radio或checkbox名称不同现实只能选择一个