現在、ページ上の特定の文字列を置き換えるために .replace 関数を使用しています。現在の文字列がどこにあるかわからないため選択できないため、コードは次のようになります。
$('body').html( $('body').html().replace(regex, 'sometext') );
したがって、元のページが次のようになっているとします。
<div class="a">Hello</div>
It now looks like this:
<div class="a">sometext</div>
を使わずに行う方法はあり$('body').html( $('body').html().replace() )
ますか?
ありがとう!
編集:例
<p class="last">Mac, iPhone, iPod and iPad customers within 90 days of ownership are eligible for complimentary phone support — one support incident per iPod and unlimited incidents per Mac, iPhone and iPad. <a href="/support/" onclick="s_objectID="http://www.apple.com/support/_3";return this.s_oc?this.s_oc(e):true">Online technical support</a> for Apple products is available beyond the initial 90 days.</p>
これを使用して:
$('body').html( $('body').html().replace("iPhone", '<a href="#">iPhone</a>') );
iPhoneの各インスタンスを置き換えて、iPhoneのように見せます
その結果:
<p class="last">Mac, <a href="#">iPhone</a>, iPod and iPad customers within 90 days of ownership are eligible for complimentary phone support — one support incident per iPod and unlimited incidents per Mac, <a href="#">iPhone</a> and iPad. <a href="/support/" onclick="s_objectID="http://www.apple.com/support/_3";return this.s_oc?this.s_oc(e):true">Online technical support</a> for Apple products is available beyond the initial 90 days.</p>