20127 月31
JS:实现复选框上下级联动
function sel(obj){ var id=obj.value; var qx=document.getElementsByName("id"); for(var i = 0; i < qx.length; i ++) { if(qx[i].type == "checkbox") { var v=qx[i].value; if(v!=""&&v.length>id.length&&v.startWith(id)){ if(obj.checked){ qx[i].checked=true; } else{ qx[i].checked=false; } } if(v!=""&&v.length<id.length&&id.startWith(v)){ if(obj.checked){ } else{ qx[i].checked=false; } } } }
<input onclick="sel(this)" type="checkbox" name="id" value="0001" />0001 <input onclick="sel(this)" type="checkbox" name="id" value="00010001" />00010001 <input onclick="sel(this)" type="checkbox" name="id" value="00010002" />00010002 <input onclick="sel(this)" type="checkbox" name="id" value="00010003" />00010003
本文地址:https://wizzer.cn/archives/2291 , 转载请保留.