2015-11-05 59 views
-1

我發現了一個很棒的jQuery高亮插件,但我需要一些修改。 我的HTML看起來像:jQuery highlight.js修改

下面是一些文字

下面是一些不同的文字

等 很多線

我想修改this插件一樣,如果有人搜索對於頁面上的單詞隱藏內容div中的所有段落只是顯示那些包含突出顯示的文本的內容。 或者,當有人搜索給一個類別的其他divs像「隱藏」或什麼的。 感謝您的幫助

回答

0

找到了答案...... 我修改這樣的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'); 
    } 
});