【问题标题】:sharepoint with JQuery - stops working when click on column filter与 JQuery 的共享点 - 单击列过滤器时停止工作
【发布时间】:2014-08-26 21:54:14
【问题描述】:

我正在使用为共享点列表中的项目行着色的代码。 当我过滤列表视图中的一列时 - JQuery 停止工作......我需要向代码中添加什么或以不同的方式编写?

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $Text = $("td.ms-cellstyle.ms-vb2:contains('Approved')"); $Text.parent().css("background-color", "#01DF3A");
        $Text = $("td.ms-cellstyle.ms-vb2:contains('Rejected')");
        $Text.parent().css("background-color", "#F90101");
        $Text = $("td.ms-cellstyle.ms-vb2:contains('Pending')");
        $Text.parent().css("background-color", "#EAC117");
    });
</script>

【问题讨论】:

    标签: jquery css sharepoint filter sharepoint-2013


    【解决方案1】:

    “$(document).ready”函数只会在页面加载时运行一次。

    当您过滤时,您正在重新创建表格中的 HTML 元素。因此,您的 jQuery 代码永远不会在这些新的 HTML 元素上运行。

    在您进行过滤以及页面加载后,您需要调用您的函数以按状态为单元格着色。

        $(document).ready(function () {
            colorCellsByStatus();
        });
    
        var colorCellsByStatus = function() {
            $Text = $("td.ms-cellstyle.ms-vb2:contains('Approved')");
            $Text.parent().css("background-color", "#01DF3A");
            $Text = $("td.ms-cellstyle.ms-vb2:contains('Rejected')");
            $Text.parent().css("background-color", "#F90101");
            $Text = $("td.ms-cellstyle.ms-vb2:contains('Pending')");
            $Text.parent().css("background-color", "#EAC117");
        }
    

    【讨论】:

      猜你喜欢
      • 2016-10-14
      • 2018-12-01
      • 1970-01-01
      • 2010-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多