开发者

jQuery button to check all check boxes issue

I have a button that checks all checkboxes in a div and un-checks.

However if I were to manually check one checkbox, then hit the Check all button and then uncheck all, the checkbox which was manually checked does not become unchecked!

Any ideas?

http://jsfiddle.net/hM5bu/1开发者_C百科/


Thats because jQuery was changed in 1.6

Using attr instead of prop is what is breaking it.

Try using prop instead

Updated fiddle: http://jsfiddle.net/hM5bu/2/

See this question: .prop() vs .attr() for more about prop and attr in jQuery 1.6


here is a solution:

<input type="checkbox" name="todos" id="todos" /> All<br/>
<input class="marcartodos" type="checkbox" name="marcado[]" value="1" />1<br/>
<input class="marcartodos" type="checkbox" name="marcado[]" value="2" />2<br/>
<input class="marcartodos" type="checkbox" name="marcado[]" value="3" />3<br/>
<input class="marcartodos" type="checkbox" name="marcado[]" value="4" />4<br/>

<script type="text/javascript">

$(function() {

$("#todos").click(function() {                          
if ($(this).is(':checked'))                         
$(".marcartodos").attr('checked', true);
else 
$(".marcartodos").attr('checked', false);
});

});

</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜