Jquery点击行(tr)选中checkbox,实现全选反选删除

点击行时效果代码:

$("tr").live("click", function () {

     if ($(this).hasClass("bgRed")) {

         $(this).removeClass("bgRed").find(":checkbox").attr("checked", false);

     } else {

                $(this).addClass("bgRed").find(":checkbox").attr("checked", true);

            }

 });

 

反选按钮时的效果代码:

$("#btnReverse").click(function () {

                //遍历.column 下的 checkbox;

                $(".column :checkbox").each(function () {

                    //给当前勾选的checkbox取反;  其中!$(this).attr("checked")是先获取他的属性,再取反,充当第二个参数;

                    //attr方法只有一个参数时是取值,两个参数时是设值;

                    $(this).attr("checked", !$(this).attr("checked"));

                    $.GetCheck($(this));  //调用自定义的函数.

                });

            });

 

自定义的函数代码:

//注意,它的位置是和$(function(){ })平级的.

 jQuery.extend({

            GetCheck: function (status) {

                $(status).attr("checked") ? $(status).parent().parent().addClass("bgRed") :       $(status).parent().parent().removeClass("bgRed");

            }

        });

如果 $(status).attr("checked") =true; 就给行添加样式 addClass("bgRed"); 如果$(status).attr("checked")=false;就把样式移除;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值