替换WKWebView中DIV标签的多行文本内容

Replace multi-line text content of DIV tag in WKWebView?

本文关键字:文本 WKWebView DIV 标签 替换      更新时间:2023-09-26

WKWebView上使用evaluateJavaScript:completionHandler:,我可以在div元素中替换单行文本,但我如何替换多行innerHTML?

<div id="MyContent"><hr>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.<br><p>It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p> <hr></div>

<div id="MyContent">Arbitrary multi-line html goes here to replace above inner html...</div>

您可以尝试替换元素的整个HTML内容。

document.getElementById("MyContent").innerHTML = "New<br />Text";