当我单击按钮时,此代码应该清除复选框。它可以工作,如果我删除<form></form>
标签,但我认为.find()
应该找到所有的后代?jquery .find()不起作用
<script type="text/javascript">
$(document).ready(function(){
var clearCheckboxes = function() {
$('.outerbox').find('input').each(function() {
$(this).attr('checked', false);
});
}
$('input.myButton').click(clearCheckboxes);
});
</script>
<div class="outerbox">
<form>
<input type="checkbox" checked="" /> checkbox1
<input type="checkbox" checked="" /> checkbox2
</form>
</div>
<input class="myButton" value="clear checkboxes now" type="button"/>
尝试使用,而不是.attr – kinakuta
它的工作显然罚款.prop - http://jsfiddle.net/gYHKA/ –
工作对我来说:HTTP://的jsfiddle .net/CgsEu/ –