jQuery:替换div中的字符串 [英] JQuery: replace a string inside a div
本文介绍了jQuery:替换div中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<div id="content">
...
<p>NUMBER times...</p>
...
<p>Place N°: NUMBER</p>
</div>
如何替换内容div中的所有NUMBER?
我尝试了replace
方法,但是没有用.
How do I replace all NUMBER inside the content div?
I tried replace
method but it didn't work.
谢谢.
推荐答案
您可以对字符串使用标准的Javascript替换功能.
You can use the standard Javascript replace function for strings.
oldhtml = $('div#content').html();
var newhtml = oldhtml.replace(/NUMBER/g, "123");
$('div.demo-container').html(newhtml);
这篇关于jQuery:替换div中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文