简体   繁体   English

jQuery数据表搜索突出显示不起作用

[英]jQuery datatable search highlight not working

I'm using jQuery datatable in our application to show tables. 我在我们的应用程序中使用jQuery数据表来显示表。 Now we want to highlight the search text which are searched by jQuery's in-built search textbox. 现在,我们要突出显示由jQuery的内置搜索文本框搜索的搜索文本。

We are using jQuery's own site for reference . 我们正在使用jQuery自己的网站作为参考

Below is our code: 下面是我们的代码:

<link rel="stylesheet" href="/css/jquery.dataTables.min.css" />
<link rel="stylesheet" href="/css/dataTables.searchHighlight.css" />
<script type="text/javascript" src="/jquery.min.js"></script>
<script type="text/javascript" src="/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/jquery.highlight.js"></script>
<script type="text/javascript" src="/dataTables.searchHighlight.min.js"></script>
<script th:inline="javascript">
$(document).ready(function() {
    var table = $('#pspTable').DataTable({
        pagingType: 'full_numbers',
        searchHighlight: true
    });
} );
</script>

However, whenever I'm running the application it's throwing the following error: 但是,每当我运行该应用程序时,都会引发以下错误:

TypeError: jQuery.highlight is not a function TypeError:jQuery.highlight不是一个函数

This is referencing to following code segment of jquery.highlight.js: 这是指jquery.highlight.js的以下代码段:

return this.each(function () {
        jQuery.highlight(this, re, settings.element, settings.className);
    });

Is there some bug in the library or I'm missing something here? 库中是否存在一些错误,或者我在这里缺少什么? Please help me with it. 请帮我。

Please open your developer tools and inspect the "Network" tab. 请打开您的开发人员工具,然后检查“网络”标签。 It seems that jquery.highlight.js wasn't loaded, because this error will only be printed if the necessary highlighting function isn't available. 似乎未加载jquery.highlight.js ,因为仅当必要的突出显示功能不可用时才会打印此错误。

I also recommend you to use datatables.mark.js instead of jquery.hightlight.js as it's cross-browser unit tested, maintained and because it uses mark.js there are many options you can use. 我还建议您使用datatables.mark.js而不是jquery.hightlight.js因为它是跨浏览器单元进行测试,维护的,并且由于它使用mark.js,因此可以使用许多选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM