的jsfiddle:http://jsfiddle.net/WM6wG/替換文本包含(比賽)
我想更換一個div文本,但似乎無法弄清楚,爲什麼它不工作。
HTML:
<div class="text">abc</div>
<div class="text">foo</div>
<div class="text">bar</div>
的jQuery:
var match = 'abc';
if ($('div.text:contains(match)')) {
$('div.text').html(function(){
$(this).replaceText(match, 'xyz');
}
}
理想預期的輸出應該是:xyz foo bar
但它仍然abc foo bar
,我究竟做錯了什麼?
' 'div.text:包含(' +匹配+ ')''只要你有'replaceText'包含的插件 – 2013-02-27 17:39:39