选中所有复选框在Javascript中第二次不起作用 [英] Check all check box does not works the second time in Javascript

查看:62
本文介绍了选中所有复选框在Javascript中第二次不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一次检查所有的复选框并且取消选中,但不在第二次。代码如下所示:

HTML

 < th align =leftwidth =25style =color:#FFF; background-color:#3A4048> 
<%= check_box_tagselect_all%>
< / th>

JQUERY

  $(#select_all)。click(function(){
$('td input [type = checkbox]')。attr('checked',this。已检查);
});

任何机构都可以帮助我解决问题



  $(function(){
)解决方案

$(#select_all)。click(function(){
$('input [type = checkbox]')。prop('checked',$(this).prop('checked'));
});
});


The check all check box first time checks and unchecks well but not at the second time. The code is as follows

HTML

<th align="left" width="25" style="color:#FFF; background-color:#3A4048">
    <%= check_box_tag "select_all" %>
</th>

JQUERY

$("#select_all").click(function () {
    $('td input[type=checkbox]').attr('checked', this.checked);
});

Can any body help me to solve the problem

解决方案

Try this:

$(function () {
    $("#select_all").click(function () {
        $('input[type=checkbox]').prop('checked', $(this).prop('checked'));
    });
});

这篇关于选中所有复选框在Javascript中第二次不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆