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

checkbox 的问题高手帮忙看看
<script>

function   chk(obj1){

var   obj   =   document.getElementsByName(obj1);
var   j   =   0;
if   (obj.length){
for   (i   =   0;   i   <   obj.length;   i++){
if   (obj[i].checked)   j++;  
if   (j   >   3){
alert( "对不起,最大选取3。 ");
obj1.checked   =   false   ;

break;

}
}
}
}
</script>

<INPUT     type= "checkbox "   name= "uid1 "     value= "1 "   onClick= "chk(this.name); ">
  <INPUT     type= "checkbox "   name= "uid1 "     value= "2 "   onClick= "chk(this.name); ">
  <INPUT     type= "checkbox "   name= "uid1 "     value= "3 "   onClick= "chk(this.name); ">
  <INPUT     type= "checkbox "   name= "uid1 "     value= "4 "   onClick= "chk(this.name); ">   <INPUT     type= "checkbox "   name= "uid1 "     value= "5 "   onClick= "chk(this.name); ">
选择超过3个提示信息点确定后,勾选为何不去掉,高手看看问题出在哪里


------解决方案--------------------
<script>

function chk(obj1){

var obj = document.getElementsByName(obj1.name);
var j = 0;

for (i = 0; i < obj.length; i++){
if (obj[i].checked) j++;
if (j > 3){
alert( "对不起,最大选取3。 ");
obj1.checked = false ;

break;

}
}
}
</script>

<INPUT type= "checkbox " name= "uid1 " value= "1 " onClick= "chk(this); ">
<INPUT type= "checkbox " name= "uid1 " value= "2 " onClick= "chk(this); ">
<INPUT type= "checkbox " name= "uid1 " value= "3 " onClick= "chk(this); ">
<INPUT type= "checkbox " name= "uid1 " value= "4 " onClick= "chk(this); ">
<INPUT type= "checkbox " name= "uid1 " value= "5 " onClick= "chk(this); ">