如何在點擊元素或其容器時(取消)檢查無線電輸入元素?如何在點擊時切換無線電輸入元素的檢查狀態?
我曾嘗試下面的代碼,但它不會取消收音機。
HTML:
<div class="is">
<label><input type="radio" name="check" class="il-radio" /> Is </label>
<img src="picture" />
</div>
的jQuery:
$(".is label, .is ").click(function() {
if (!$(this).find(".il-radio").attr("checked")) {
$(this).find(".il-radio").attr("checked", "checked");
} else if ($(this).find(".il-radio").attr("checked") == "checked") {
$(this).find(".il-radio").removeAttr("checked");
}
});
你爲什麼不只是使用標籤在其原來的形式? http://www.w3schools.com/tags/tag_label.asp – 2012-03-16 13:27:47
@OriesokVlassky:因爲這需要每個輸入控件都有一個ID,以便標籤引用它。 ''是有效的HTML;它應該工作。 – cHao 2012-03-16 13:31:35
檢查http://stackoverflow.com/questions/2117538/jquery-how-to-uncheck-a-radio-button – 2012-03-16 14:04:09