我們如何選中或取消選中複選框上點擊所有單選按鈕。如果選中複選框,那麼所有單選按鈕也查了,反之亦然..它不能正常檢查單選按鈕上的複選框更改事件
<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)。 –