是否有一种直接的方法在div中搜索特定字符串并将其替换为另一个字符串?我不能单独使用.replaceWith,因为我需要保留div中的其他元素.我试过这里找到的各种javascript方法无济于事.
所以类似于:
$('#foo').find('this string').replaceWith('this other string');
Run Code Online (Sandbox Code Playgroud)
对于:
<div id="foo"><div id="child">Other Element</div>this string</div>
Run Code Online (Sandbox Code Playgroud)
谢谢.