查詢文字並高亮

2021-08-25 16:27:28 字數 736 閱讀 5358

讓我們來看一下如何使用 jquery 去查詢或搜尋一段文字並高亮它。

我是 jquery 的忠實粉絲,喜歡它簡介的語法。接下來讓我演示乙個示例:僅使用一行 jquery **便可把搜尋字段進行高亮。

divone. this is a ****** looking div

divtwo. this is another ****** looking div

divthree. this is just a div

divfour. this is again a div

divfive. yet another ****** looking div

這裡我們使用 jquery 中的 contains 選擇器來在被鎖定的元素及這些元素的後代中進行特定字元的查詢。

如果 div 標籤內包含 「******」 文字,那麼該 div 標籤將會被高亮:寬度變為 4px,這些只需要一行**。

顯示結果

改進版本:

$("div:contains('******')"

).html($("div:contains('******')"

).html().replace(/******/g, "******"));

改進自:

本文是使用

b3log solo 從

vanessa 進行同步發布的

查詢文字並高亮

讓我們來看一下如何使用 jquery 去查詢或搜尋一段文字並高亮它。我是 jquery 的忠實粉絲,喜歡它簡介的語法。接下來讓我演示乙個示例 僅使用一行 jquery 便可把搜尋字段進行高亮。divone.this is a looking div divtwo.this is another lo...

solr查詢列表並高亮顯示

private mapsearchlist map searchmap 1.3按品牌篩選 if equals searchmap.get brand 1.4按規格篩選 if searchmap.get spec null 1.5 篩選 if equals searchmap.get price if...

lucene 多欄位查詢 文字高亮顯示

先建立索引,lucene3.0 directory directory null indexsearcher isearcher null analyzer analyzer new ikanalyzer directory new fsdirectory new file d data isear...