如何使用javascript根据其他Checkbox设置输入复选框的选中值 [英] How to set the checked value of an input Checkbox according to other Checkbox using javascript
本文介绍了如何使用javascript根据其他Checkbox设置输入复选框的选中值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
i我在我的设计中使用了三个输入类型=复选框,现在复选框是这样的
所有
1
2
默认选中全部。我想要的是,当我选择1或2时,我想要取消选中全部选项。
我的HtMl代码:
< li >
< h5 class = booking-filters- title > abc < / h5 >
< div class = 复选框 >
< label >
< 输入 id = chkAny class = i-check < span class =code-attribute> runat = server type = 复选框 / > 所有
< / label >
< / div >
< div < span class =code-attribute> class = 复选框 >
< 标签 >
< 输入 id = chkOne class = i-check runat = server type = 复选框 / > 1
< / label >
< / div >
< div class = 复选框 >
< label >
< input id = chkTwo class = 我检查 runat = server 类型 = 复选框 / > 2
< / label >
< / div >
< / li >
我是使用Bootstrap,我希望它通过java脚本完成。
问候
Syed
解决方案
这实际上是一个简单的解决方案,下次仔细思考问题并先尝试一下,你会发现它并不复杂!这应该工作
< li >
< h5 class = booking-filters-title > Abc < / h5 >
< div class = 复选框 >
< label >
< input id = chkAny class = i-check runat = server type = 复选框 checked / > 所有
< / label >
< / div >
< div 类 = 复选框 > ;
< label >
< input id = chkOne onclick = chkMe(); class = i-check runat = server type = 复选框 选中/ > 1
< / label >
< / div >
<div class = 复选框 >
< label >
< input id = chkTwo onclick = chkMe(); 类 = i-check runat = 服务器 类型 = 复选框 已选中/ > 2
< / label >
< / div >
< / li >
< 脚本 >
function chkMe()
{
if(document.getElementById(chkOne)。checked == true&& document.getElementById(chkTwo)。checked == true)
document.getElementById(chkAny)。checked = true;
else
document.getElementById(chkAny)。checked = false;
}
< / script > 跨度>
Hi
i am using three input whose type=checkbox in my design, now the check boxes are like this
All
1
2
All is checked by default. What i want is that when i select either 1 or 2 i want the "All" option to be unchecked.
My HtMl code:
<li>
<h5 class="booking-filters-title">Abc</h5>
<div class="checkbox">
<label>
<input id="chkAny" class="i-check " runat="server" type="checkbox" />All
</label>
</div>
<div class="checkbox">
<label>
<input id="chkOne" class="i-check" runat="server" type="checkbox" />1
</label>
</div>
<div class="checkbox">
<label>
<input id="chkTwo" class="i-check" runat="server" type="checkbox" />2
</label>
</div>
</li>
I am using Bootstrap and I want it to be done via java script.
Regards
Syed
解决方案
It's actually a simple solution, next time think through the problem and attempt something first and you will discover it's not that complicated! This should work
<li> <h5 class="booking-filters-title">Abc</h5> <div class="checkbox"> <label> <input id="chkAny" class="i-check " runat="server" type="checkbox" checked/>All </label> </div> <div class="checkbox"> <label> <input id="chkOne" onclick="chkMe();" class="i-check" runat="server" type="checkbox" checked/>1 </label> </div> <div class="checkbox"> <label> <input id="chkTwo" onclick="chkMe();" class="i-check" runat="server" type="checkbox" checked/>2 </label> </div> </li> <script> function chkMe() { if(document.getElementById("chkOne").checked == true && document.getElementById("chkTwo").checked == true) document.getElementById("chkAny").checked = true; else document.getElementById("chkAny").checked = false; } </script>
这篇关于如何使用javascript根据其他Checkbox设置输入复选框的选中值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文