2013-01-12 81 views
-9

實例替換我有這樣的代碼:搜索文本,並用JavaScript

<div class="description"> I make you smile. </div> 

轉化到:

<div class="description"> I make you think. </div> 

注: 「微笑」 替換爲 「思考」

如何我用javascript jQuery替換它?可以更改幾個詞嗎?

+0

問題表明缺乏事先搜索EFORT的......類似的帖子可能100的這裏已經 – charlietfl

+0

抱歉,謝謝你。 – Genial

回答

4
var ele = $("div.description");      //Let ele be target element 
ele.html(ele.html().replace(/smile/gi,"think")); //Replace the word in string, 
                // then put it back in. 

.replaceMDN

演示:http://jsfiddle.net/DerekL/FdyEH/

+1

謝謝!你真棒! – Genial