【发布时间】:2013-07-04 08:43:56
【问题描述】:
我有具有图像、标签和输入复选框的 div。当我点击 div 时,我喜欢什么,它会将复选框状态从 true 更改为 false 和虎钳
jQuery
$(".markerDiv").click(function () {
if ($(this).find('input:checkbox[name=markerType]').is(":checked")) {
$(this).find('input:checkbox[name=markerType]').attr("checked", false);
}
else {
$(this).find('input:checkbox[name=markerType]').attr("checked", true);
}
alert($(this).find('input:checkbox[name=markerType]').is(":checked"));
});
html
<div class="markerDiv" id="maker_school"><label class="marker_label">School</label> <input class="marker_ckeckbox" name="markerType" value="school" type="checkbox" /> </div> <br />
【问题讨论】:
-
yh 但是当您继续点击学校时,它会停止运行...
-
您的目标是哪个版本的 IE?您可以使用 :checked 伪类在纯 css 中执行此操作
-
评论接受的答案为什么你选择它而不是其他人的