【问题标题】:Data table multiple row selection数据表多行选择
【发布时间】:2011-02-03 05:38:03
【问题描述】:

单击复选框时如何更改行的背景颜色?

【问题讨论】:

    标签: javascript css jsf datatable


    【解决方案1】:

    为此,您需要一些 Javascript。

    <h:selectBooleanCheckbox onclick="highlightRow(this)">
    

    function highlightRow(checkbox) {
        getParentByTagName(checkbox, 'tr').style.background = (checkbox.checked) ? '#6f6' : 'none';
    }
    function getParentByTagName(element, tagName) {
        var p = element.parentNode;
        return p ? ((p.tagName.toLowerCase() == tagName.toLowerCase()) ? p : getParentByTagName(p, tagName)) : false;
    }
    

    或者如果你已经在使用jQuery

    function highlightRow(checkbox) {
        $(checkbox).closest('tr').css('background', checkbox.checked ? '#6f6' : 'none');
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-21
      • 2023-03-14
      • 2017-01-26
      • 2015-07-06
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多