我喜欢单击一个标签并选中前面的复选框。我已经尝试了下一个代码,但这不起作用。我已经尝试了 2 个小时,但我错过了什么?
JQUERY
jQuery(document).ready(function() {
$('.namelabel').live('click', function() {
if ($(this).prev("input:checked").val() != null) {
$(this).prev("input").removeAttr("checked");
} else {
$(this).prev("input").attr("checked","checked");
}
});
});
HTML
<input type="checkbox" class="check" name="example" /> <img src="image.png" class="modelinfo" /> <label class="namelabel">John Doe</label>
谁能帮我解决这个问题?非常感谢!
ps 我知道我可以用标签轻松解决这个<label for="">
问题,但这不是问题。