Hey I have two issues with this following code.
First of all when I check the checkbox number 3 it automatically checks number 2, I only want that if I check it my self (Like when I check checkbox number 2). The second issue is I can't uncheck a checkbox after checking it.
var cbs = document.getElementsByName("test"); function demo(obj) { var hzp = cbs[1]; var ht = cbs[2]; for (var i = 0; i < cbs.length; i++) { if(cbs[i].value == hzp.value || cbs[i].value === ht.value) { if(cbs[i].value == obj.value) { if(cbs[i].checked && hzp.checked || ht.checked) { hzp.checked = true; ht.checked = true; } } } cbs[i].checked = false; } obj.checked = true; } checkbox 1 <input type="checkbox" name="test" id="demo1" value="demo01" onClick="demo(this)"> checkbox 2 <input type="checkbox" name="test" id="demo2" value="demo02" onClick="demo(this)"> checkbox 3 <input type="checkbox" name="test" id="demo3" value="demo03" onClick="demo(this)"> checkbox 4 <input type="checkbox" name="test" id="demo" value="demo04" onClick="demo(this)">
没有评论:
发表评论