替换WKWebView中DIV标签的多行文本内容?
Posted
技术标签:
【中文标题】替换WKWebView中DIV标签的多行文本内容?【英文标题】:Replace multi-line text content of DIV tag in WKWebView? 【发布时间】:2015-10-05 05:09:45 【问题描述】:在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>
【问题讨论】:
【参考方案1】:您可以尝试替换元素的整个 HTML 内容。
document.getElementById("MyContent").innerHTML = "New<br />Text";
【讨论】:
以上是关于替换WKWebView中DIV标签的多行文本内容?的主要内容,如果未能解决你的问题,请参考以下文章
如何在swift 4中从WKWebView中的网页中删除DIV标签?
在javascript中搜索和替换div的html内的文本,而不是标签内的文本