我们如何选中或取消选中复选框上点击所有单选按钮。如果选中复选框,那么所有单选按钮也查了,反之亦然..它不能正常检查单选按钮上的复选框更改事件
<input type="checkbox" id="Check" />SelectAll<br /><input type="radio"/>First<br />
<input type="radio"/>Second<br />
<input type="radio"/>Third<br />
<input type="radio"/>Fourth<br />
<input type="radio"/>Fifth</div>
<script>
var IsCheck = false;
$(document).ready(function() {
$("#Check").change(function() {
if (IsCheck == false) {
$("input[type=radio]").attr("checked", true);
IsCheck == true
}
else { $("input[type=radio]").attr("checked", false); IsCheck == false }
});
}); </script>
我不认为广播是正确的选择HTTP:/ /en.wikipedia。org/wiki/Radio_button通常只选择一个组中的一个选项 – HMR
请不要对此使用单选按钮 – Jonathan
(重要)注意:'var IsCheck = false;'引入一个全局变量,[这是一件坏事]( http://stackoverflow.com/questions/10525582/why-are-global-variables-considered-bad-practice-javascript)。将你的JavaScript代码封装在[自我调用函数]中(http://stackoverflow.com/questions/15313163/javascript-self-invoking-function)。 –