Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这是我的html:
<div id="ref"> <p>.....</p> <p>.....</p> abcd </div>
我想将“abcd”文本更改为其他一些文本,例如“wxyz”。我如何才能遍历该文本,尤其是在 jquery 中?
我是笼统地问这个问题,不一定总是“abcd”或“wxyz”
$("#ref").contents().last()[0].nodeValue = "wyxz";
http://jsfiddle.net/rWss5/
$(function(){ var text = $('#ref').text(); text = text.replace("abcd", "wxyz"); $('#ref').text(text); });
http://jsfiddle.net/t2saH/