如何在点击元素或其容器时(取消)检查无线电输入元素?如何在点击时切换无线电输入元素的检查状态?
我曾尝试下面的代码,但它不会取消收音机。
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