wenzhixin bootstrap-table 點擊table單元格改變顏色

bootstrap-table用於展現數據很是方便,也須要知足一些個性化需求。好比點擊窗格(td)標記下顏色,用於目測bootstrap

代碼以下,轉載請註明spa

$("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';
                }
            });

解釋:code

click-row.bs.table是行點擊事件,其實還有個click-cell.bs.table點擊窗格事件,但$el是string沒法使用blog

$el是被點擊的行,$el.context是被點擊的窗格屬性。經過children尋找該行下那個被點的子元素td並添加樣式事件

相關文章
相關標籤/搜索