可能重複:
Find text string in jQuery and make it bold如何使用jQuery:包含(某些文本)選擇器,但僅從「這是一些文本」中選擇「某些文本」?
如何使用jQuery的:包含(一些文本)選擇,但只有選擇 「一些文本」,從 「這是一些文本」?
我有這樣的事情:
<div class="search">this is some text</div>
我目前使用這樣的代碼:
$("div.search:contains(some text)").css("text-decoration","underline");
但是,強調「這是一些文本」,我希望它只是強調「一些文本」。
我該如何做到最簡單?
NOP,不能做這種方式,需要一些正則表達式魔術至少,檢查出http://stackoverflow.com/questions/9794851/find-text-string-in-jquery-and -make-it-bold/9795091#9795091 – elclanrs
您正在將css應用於div - 不是文本,因此行爲是正確的。你可以拆分'.html()'並用它想要的樣式包裝一個''。 – Nic