-1
我发现了一个很棒的jQuery高亮插件,但我需要一些修改。 我的HTML看起来像:jQuery highlight.js修改
下面是一些文字
下面是一些不同的文字
等 很多线
我想修改this插件一样,如果有人搜索对于页面上的单词隐藏内容div中的所有段落只是显示那些包含突出显示的文本的内容。 或者,当有人搜索给一个类别的其他divs像“隐藏”或什么的。 感谢您的帮助
我发现了一个很棒的jQuery高亮插件,但我需要一些修改。 我的HTML看起来像:jQuery highlight.js修改
下面是一些文字
下面是一些不同的文字
等 很多线
我想修改this插件一样,如果有人搜索对于页面上的单词隐藏内容div中的所有段落只是显示那些包含突出显示的文本的内容。 或者,当有人搜索给一个类别的其他divs像“隐藏”或什么的。 感谢您的帮助
找到了答案...... 我修改这样的JavaScript:
$(function() {
jQuery('#text-search').bind('keyup change', function(ev) {
// pull in the new value
var searchTerm = jQuery(this).val();
// remove any old highlighted terms
jQuery('.toggle').removeHighlight();
// line to remove the hidden class
jQuery(".toggle p").removeClass("hidden")
// disable highlighting if empty
if (searchTerm) {
// highlight the new term
jQuery('.toggle').highlight(searchTerm);
//line to add the hidden class
jQuery('.toggle p:not(:contains('+ searchTerm +'))').closest('p').addClass('hidden');
}
});