检查类的动态Bootstrap表

时间:2017-08-04 10:02:43

标签: javascript jquery html twitter-bootstrap bootstrap-4

所以我得到了这张桌子

<table id="table" class="table table-bordered table-hover">
    <thead>
        <tr>
            <th data-field="id" class="hidden">ID</th>
            <th data-field="variant">Variant</th>
            <th data-field="description">Description</th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>

将填充数据

$('#table').bootstrapTable({
    data: returnValue
});

然后我可以点击将向其添加类.bg-info的行,我想检查一行是否有该类,然后将行数据保存在var

这是我的尝试:

var item = $.map(table.rows('.bg-info').data(), function (item) {
    return item[0]
});

但是table.rows显然不能用作方法

1 个答案:

答案 0 :(得分:0)

If you want to select all the rows with the class bg-info in your table. Use a jQuery selector based on that class :

var bgInfoRows = $("#table tbody .bg-info");

You will have every item in tbody that has the class bg-info.