현재 페이지의 특정 문자열을 바꾸려면 .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>'));
을
것은 내가 일반적으로 그것을 만들려고한다을 가능한 한 너무 모든 페이지에서 작동 할 수 있습니다. 게시물을 예를 들어 편집했습니다. – jsllsj
이렇게하면보다 간결한 방법을 찾고 있습니까? –
전체 dom을 교체하지 않고이를 수행 할 방법을 찾고 있습니다. 이것은 그 안에 js가있는 많은 페이지를 망가 뜨리는 것 같습니다. – jsllsj