[英]Difference between innerhtml and outerhtml in cocoa WebView
我在我的应用程序中使用cocoa webview进行富文本编辑。 只是与webkit中可用的innerHtml和outerHtml方法混淆。
任何人都可以解释有什么区别
[(DOMHTMLElement *)[[[webView mainFrame] DOMDocument] documentElement] outerHTML];
和
[(DOMHTMLElement *)[[[webView mainFrame] DOMDocument] documentElement] outerText];
innerHTML是DOM元素的一个属性,表示元素内部的HTML,即开始和结束标记之间的HTML。 它已被广泛复制,但实现方式各不相同(可能因为它没有公布的标准[1]),尤其是它们如何处理元素属性。
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
假设我们有一个用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为
标题为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
我已经在示例的帮助下对其进行了解释,其中这四个术语的定义已经在下面的答案中解释过了。
<!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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.