私は現在、ページ上の特定の文字列を置き換えるために.replace関数を使用しています。 jQueryを使用して文字列を置き換える置換と正規表現
$('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>
:
<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>
:
$('body').html($('body').html().replace("iPhone", '<a href="#">iPhone</a>'));
それはiPhone
に結果ののようになりますように、それはiPhoneの各インスタンスを置き換えます
の事、私はジェネリックとしてそれを作るしようとしているさを可能な限りそれそうどのページでも動作します。私は例を使って投稿を編集しました。 – jsllsj
これを行うためのより簡潔な方法をお探しですか? –
私はDOM全体を交換することなくそれを行う方法を探しています。これは、その中にjsを持つ多くのページを破るようです。 – jsllsj