jquery - 与 JQuery 的共享点 - 单击列过滤器时停止工作

标签 jquery css sharepoint filter sharepoint-2013

我正在使用一个代码为共享点列表中的元素行着色。 当我过滤 ListView 中的一列时 - 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>

最佳答案

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

关于jquery - 与 JQuery 的共享点 - 单击列过滤器时停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24593264/

相关文章:

javascript - 单击按钮时不调用 Jquery

iphone - webkit 溢出滚动触摸与 webkit 转换冲突

sharepoint - 如何在 Event Handler 中获取 HttpContext

c# - 如何在 SharePoint 中读取具有多个值的 LookUp 字段?

javascript - 根据日期和时间标准显示网页

jQuery:以最优雅、最高效的方式弹出 float 信息

css - 将 Angular 中的标题大写

javascript - 如何使用 JavaScript 检索文档集的元数据

javascript - 使事件在第一次单击的元素上发生,但仅当单击另一个元素时才再次触发该事件

html - 浏览器如何计算具有百分比宽度或高度的元素的大小