bootstrap table onUncheck选中行事件

bootstrap table取消选择的事件,onUncheck事件返回取消选择行的数据和被点击的元素对象。

onUncheck取消选中行事件

取消选中复选框的事件,返回参数如下。

参数名称说明
row选中行的数据对象json格式如{name:"西瓜",num:9}
$element被点击的jquery对象

绑定onUncheck事件方法一

$('#table').bootstrapTable({
    columns: columns, //列对象
    data: data, //要显示的数据对象
    onUncheck:function(row, $element){
                alert(JSON.stringify(row));
    }
 });

绑定onUncheck事件方法二

$('#table').on('uncheck.bs.table', function (e,row, $element) {
      alert(JSON.stringify(row));
});

注意:初始化时注册和初始化后注册的第一个返回参数对象是不一样的

完整代码

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <script src="https://www.itxst.com/package/bootstrap-table-1.14.1/jquery-3.3.1/jquery.js"></script>
    <link href="https://www.itxst.com/package/bootstrap-table-1.14.1/bootstrap-4.3.1/css/bootstrap.css" rel="stylesheet" />
    <link href="https://www.itxst.com/package/bootstrap-table-1.14.1/bootstrap-table-1.14.1/bootstrap-table.css" rel="stylesheet" />
    <script src="https://www.itxst.com/package/bootstrap-table-1.14.1/bootstrap-table-1.14.1/bootstrap-table.js"></script>
    <title>bootstrap table onUncheck取消选中行事件在线例子</title>
    <style>
        .table-demo {
            width: 90%;
            margin: 50px auto 0px auto;
        }
    </style>
</head>
<body>
    <div class="table-demo">
        <table id="table"></table>
    </div>
    <script>
        //设置需要显示的列
        var columns = [{
            checkbox: true
        }, {
            field: 'Name',
            title: '名称'
        }, {
            field: 'Num',
            title: '销量'
        }];


        //需要显示的数据
        var data = [{
            Id: 1,
            Name: '橘子',
            Num: '5'
        }, {
            Id: 2,
            Name: '西瓜',
            Num: '6'
        }];
        //bootstrap table初始化数据
        $('#table').bootstrapTable({
            singleSelect: false,
            clickToSelect: true,
            columns: columns,
            data: data,
            onUncheck: function (row, $element) {
                alert(JSON.stringify(row));
            }
        });
             // $('#table').on('uncheck.bs.table', function (e,row, $element) {
             // alert(JSON.stringify(row));
             // })
    </script>
</body>
</html>

在线试一试