wenzhixin bootstrap-table 点击table单元格改变颜色

bootstrap-table用于展示数据非常方便,也需要满足一些个性化需求。比如点击窗格(td)标记下颜色,用于目测

代码如下,转载请注明

$("table").on('click-row.bs.table', function (e, row, $el) {
                //el['0'] is tr   $el is selected ele
                if ($el['0'].children[$el.context.cellIndex].className) {
                    $el['0'].children[$el.context.cellIndex].className = '';
                } else {
                    $el['0'].children[$el.context.cellIndex].className = 'success';
                }
            });

解释:

click-row.bs.table是行点击事件,其实还有个click-cell.bs.table点击窗格事件,但$el是string无法使用

$el是被点击的行,$el.context是被点击的窗格属性。通过children寻找该行下那个被点的子元素td并添加样式

posted @ 2017-07-05 16:14  Els0n  阅读(1170)  评论(0编辑  收藏  举报