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.
var gethtml = $("#topmenu > li.l89 a").text().split(' ')[1].replaceWith('Any World');
即使使用replaceWith如上所示,文本也不会改变。
replaceWith
调用 .text() 后,您不再使用 jQuery 对象,而是使用纯字符串。你可以这样做...
var text = $("#topmenu > li.l89 a").text() , textParts = text.split(' '); textParts[1] = "Any world"; console.log('New text', textParts.join(" "));
我写了长版给你看步骤。如果你愿意,你可以在一行上做,但它不再可读了。