1
我正在使用Greasemonkey和waitForKeyElements()
來更改網頁中的一些文本。使用waitForKeyElements使用跨度包裝文本正在消除樣式?
這裏是一個單一的jNode元素的例子。
<div class="Ov-h Mx-a">
<div>
<div class="Grid-bind-end">
<div class="ysf-player-name Nowrap Grid-u Relative Lh-xs Ta-start">
<a class="Nowrap" href="http://sports.yahoo.com/nfl/players/7206" target="sports">H. Miller</a> <span class="Fz-xxs">Pit - TE</span>
</div>
</div>
<div class="Grid-bind-end">
<span class="ysf-player-status F-injury Fz-xxs Grid-u Lh-xs"></span>
<div class="ysf-player-detail Nowrap Grid-u Fz-xxs Lh-xs Ta-start">
<span class="ysf-game-status"><a class="F-reset" href="http://sports.yahoo.com/nfl/pittsburgh-steelers-new-england-patriots-20150910017/" onclick="pop(this)" target="sports">Thu 5:30 pm @ NE</a></span>
</div>
</div>
</div>
</div>
我想改變Thu 5:30 pm @ NE
到Thu 5:30 pm @ < span class="color">NE - [rank]</span>
(注意[排名]是一個變量我有)
這是我曾嘗試
jNode.text((jNode.text().replace("NE","<span class='color'>NE - [rank]</span>")))
但是,這使該元素失去它的造型。
好了,這種包裝的 - 的*文本*,在單個節點 - '中是罕見的上下的地方它是好的,使用jQuery的'的.html()的一個userscript。有「純粹的」DOM方法,但只要被替換的節點沒有子節點或事件處理程序,缺點是很小,而.html()通常更清晰和簡單。 –