我使用cocoa webview在我的应用程序中进行富文本编辑。只是混淆了webkit中提供的innerHtml和outerHtml方法。
有没有人能解释一下
[(DOMHTMLElement *)[[[webView mainFrame] DOMDocument] documentElement] outerHTML];和
[(DOMHTMLElement *)[[[webView mainFrame] DOMDocument] documentElement] outerText];发布于 2013-01-10 19:15:45
innerHTML是DOM元素的一个属性,表示元素内部的HTML,即开始标记和结束标记之间的属性。它已经被广泛复制,但是实现各不相同(可能是因为它没有发布的standard1),特别是在处理元素属性的方式上。
outerHTML类似于innerHTML,它是一个元素属性,包括开始和结束标记以及内容。它没有像innerHTML那样被广泛复制,所以它或多或少只保留了IE。
<p id="pid">welcome</p>
innerHTML of element "pid" == welcome
outerHTML of element "pid" == <p id="pid">welcome</p>鉴于
innerText容器的文本内容。
当被访问用于读取时,outerText与innerText相同;当分配一个新值时,替换整个元素。
<p id="pid">welcome</p>
innerText of element "pid" == welcome
outerText of element "pid" == welcome发布于 2013-01-10 19:56:40
假设我们有一个用html加载到webview的页面。
<html>
<head><title>Your Title</title></head>
<body>
<h1>Heading</h1>
<p id="para" >hi <b>Your_Name</b></p>
</body>
<html>现在。
[(DOMHTMLElement *)[[webView mainFrame] DOMDocument] documentElement] 将返回DOMHTMLElement "html“和
outerHTML将返回完整的html为
<html>
<head><title>Your Title</title></head>
<body>
<h1>Heading</hi>
<p id="para">hi <b>Your_Name</b></p>
</body>
<html>outerText将返回html为
标题: hi Your_Name
例如,如果我们以本例中的p标记为例
outerHTML will return - <p id="para">hi <b>Your_Name</b></p>
outerText will return - hi Your_Name
innerHTML will return - hi <b>Your_Name</b>
innerText will return - hi Your_Name我已经通过示例解释了它,其中这4个术语的定义已经在下面的答案中解释过了。
发布于 2017-11-24 05:48:32
<!DOCTYPE html>
<html>
<head>
<title>innerHTML and outerHTML | Javascript Usages</title>
</head>
<body>
<div id="replace">REPLACE By inner or outer HTML</div>
<script>
userwant = "inner";
userwant = "outer";
if (userwant = "inner") {
document.querySelector("#replace").innerHTML;
// this will remove just message: 'REPLACE By inner or outer HTML' //
} else if (userwant = "outer") {
document.querySelector("#replace").outerHTML;
// this will remove all element <div> ~ </div> by the message: 'REPLACE By inner or outer HTML' //
};
</script>
</body>
</html>
https://stackoverflow.com/questions/14256102
复制相似问题