简体   繁体   English

cocoa WebView中innerhtml和outerhtml的区别

[英]Difference between innerhtml and outerhtml in cocoa WebView

I am using cocoa webview for rich text editing in my application. 我在我的应用程序中使用cocoa webview进行富文本编辑。 Just confused with innerHtml and outerHtml method avaiable in webkit. 只是与webkit中可用的innerHtml和outerHtml方法混淆。

Can anyone explain what is the difference between 任何人都可以解释有什么区别

[(DOMHTMLElement *)[[[webView mainFrame] DOMDocument] documentElement] outerHTML];

AND

[(DOMHTMLElement *)[[[webView mainFrame] DOMDocument] documentElement] outerText];

innerHTML is a property of a DOM element that represents the HTML inside the element, ie between the opening and closing tags. innerHTML是DOM元素的一个属性,表示元素内部的HTML,即开始和结束标记之间的HTML。 It has been widely copied, however implementations vary (probably because it has no published standard[1]) particularly in how they treat element attributes. 它已被广泛复制,但实现方式各不相同(可能因为它没有公布的标准[1]),尤其是它们如何处理元素属性。

outerHTML is similar to innerHTML, it is an element property that includes the opening an closing tags as well as the content. outerHTML类似于innerHTML,它是一个元素属性,包括打开结束标记以及内容。 It hasn't been as widely copied as innerHTML so it remains more-or-less IE only. 它没有像innerHTML那样被广泛复制,所以它只是或多或少的IE。

<p id="pid">welcome</p>

innerHTML of element "pid" == welcome
outerHTML of element "pid" == <p id="pid">welcome</p>

and whereAs 和哪里作为

innerText The textual content of the container. innerText容器的文本内容。

outerText Same as innerText when accessed for read; outerText在读取时与innerText相同; replaces the whole element when assigned a new value. 分配新值时替换整个元素。

<p id="pid">welcome</p>

innerText of element "pid" == welcome
outerText of element "pid" == welcome

Suppose we have a page loaded to webview with html 假设我们有一个用html加载到webview的页面

<html>
<head><title>Your Title</title></head>
<body>
<h1>Heading</h1>
<p id="para" >hi <b>Your_Name</b></p>
</body>
<html>

NOW. 现在。

[(DOMHTMLElement *)[[webView mainFrame] DOMDocument] documentElement] 

will returen the DOMHTMLElement "html" and 将返回DOMHTMLElement“html”和

outerHTML will return the complete html as 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 will return html as outerText将返回html为

Heading hi Your_Name 标题为Your_Name

for example if we take example of p tag in this case 例如,如果我们在这种情况下采用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

i have explained it with the help of example where definition for these 4 terms already explained in the answer below. 我已经在示例的帮助下对其进行了解释,其中这四个术语的定义已经在下面的答案中解释过了。

 <!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.

相关问题 碳和可可之间的区别? - difference between carbon and cocoa? 可可中操作和线程之间的区别 - Difference between operations & threads in Cocoa 可可中的类集群和抽象工厂之间的区别 - Difference between class clusters and abstract factory in cocoa Reactive Cocoa中RACAble(),RACObserve()和RACBind()之间的区别 - Difference between RACAble(), RACObserve() and RACBind() in Reactive Cocoa Morphic中的Morph和可可中的NSView有什么区别? - What is the difference between a Morph in Morphic and a NSView in Cocoa? Cocoa:在标题中导入和在主文件中导入之间有什么区别? - Cocoa: What's the difference between importing in the header and importing in the main file? Xcode,Objective-C和Cocoa有什么区别? - What’s the difference between Xcode, Objective-C and Cocoa? 可可 - -removeObserver:forKeyPath:和-removeObserver:forKeyPath:context:?之间的细微差别 - cocoa - Subtle difference between -removeObserver:forKeyPath: and -removeObserver:forKeyPath:context:? Objective-C和Cocoa有什么区别? - What's the difference between Objective-C and Cocoa? 使用OpenSSL的bash脚本和可可代码之间的区别 - Difference between bash-script and cocoa code with OpenSSL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM