今天帮同学实现了这一个要求,用Javascript把Checkbox实现类似于 radio 的效果
<
html
>
< head >
< title > Demo By hooyes </ title >
< script language ="javascript" type ="text/javascript" >
function addCustomCheckBox(){
var checkBoxName = " Checkbox " ;
var c = document.getElementsByName(checkBoxName);
for ( var k = 0 ;k < c.length;k ++ ){c[k].attachEvent( " onclick " ,hooyesFnX(k));}
function hooyesFnX(x){ return function (){ for ( var l = 0 ;l < c.length;l ++ ){ if (x != l){c[l].checked = false ;}}}}
}
</ script >
</ head >
< body onload ="addCustomCheckBox();" >
< input id ="Checkbox1" name ="Checkbox" type ="checkbox" /> 男
< input id ="Checkbox2" name ="Checkbox" type ="checkbox" /> 女
< input id ="Checkbox3" name ="Checkbox" type ="checkbox" /> 火星人
</ body >
</ html >
< head >
< title > Demo By hooyes </ title >
< script language ="javascript" type ="text/javascript" >
function addCustomCheckBox(){
var checkBoxName = " Checkbox " ;
var c = document.getElementsByName(checkBoxName);
for ( var k = 0 ;k < c.length;k ++ ){c[k].attachEvent( " onclick " ,hooyesFnX(k));}
function hooyesFnX(x){ return function (){ for ( var l = 0 ;l < c.length;l ++ ){ if (x != l){c[l].checked = false ;}}}}
}
</ script >
</ head >
< body onload ="addCustomCheckBox();" >
< input id ="Checkbox1" name ="Checkbox" type ="checkbox" /> 男
< input id ="Checkbox2" name ="Checkbox" type ="checkbox" /> 女
< input id ="Checkbox3" name ="Checkbox" type ="checkbox" /> 火星人
</ body >
</ html >