[英]replace a text with another within a tag
我敢肯定這很簡單,但是如何只替換html標簽中的文本。 例如,從此:
<div style="display: block;">blah blah</div>
<a href="#" style="display: inline; ">(Old text)</a>
對此:
<div style="display: block;">blah blah</div>
<a href="#" style="display: inline; ">(New text)</a>
替換舊文本=>新文本
提前謝謝了。
在包含文本的元素上放置一個id:
<div style="display: block;">blah blah</div><a href="#" style="display: inline; " id="replaceme">(Old text)</a>
並使用
$('#replaceme').html('New text');
這是基本的,我想您可以從這里解決:)
首先,給您的元素一個ID,以便您可以引用它:
<a id="something" href="#" style="display: inline; ">(Old text)</a>
然后使用字符串replace
功能:
var str = $('#something').text();
$('#something').text(str.replace('Old text', 'New text'));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.