我想在HTML文档中查找和替换文本,比如在 <title> 标签内部。例如,
var str = "<html><head><title>Just a title</title></head><body>Do nothing</body></html>";
var newTitle = "Updated title information";
我尝试使用 jQuery 中的 parseXML()(以下是示例),但它无法正常工作:
var doc= $($.parseXML(str));
doc.find('title').text(newTitle);
str=doc.text();
在HTML标签内查找和替换文本的其他方法是否存在?可以使用正则表达式或者replaceWith()等类似方法吗?