textContent,innerText、innerHTML和outerHTML區別
本章節簡單介紹一下標題中三個屬性的用法和區別,需要的朋友可以做一下參考。
(1).innerHTML屬性用來讀取或設定某個節點內的HTML程式碼。
(2).outerHTML屬性用來讀取或設定HTML程式碼時,會把節點本身包括在內。
(3).textContent屬性用來讀取或設定節點包含的文字內容。
主要區別如下:
(1).innerText屬性和outerText屬性在讀取元素節點的文字內容時,得到的值是不一樣的。
(2).它們的不同之處在於設定一個節點的文字屬性時,outerText屬性會使得原來的元素節點被文字節點替換掉。
(3).innerText受CSS影響,textcontent沒有這個問題。比如,如果CSS規則隱藏了某段文字,innerText就不會返回這段文字,textcontent則照樣返回。
(4).innerText返回的文字,會過濾掉空格、換行和Enter鍵,textcontent則不會。
特別說明:innerText是非標準屬性,Firefox不支援。
相關文章
- innerHTML,outerHTML,innerText,outerTextHTML
- innerHTML 和 innerTEXT 區別HTML
- innerText和textContent的區別
- innerText 和 textContent 的區別?
- innerText與textContent區別
- innerText和innerHTML區別簡單程式碼例項HTML
- innerText和innerHTML的區別以及JS函式總結HTMLJS函式
- textarea中的innerHtml,innerText和valueHTML
- outerText和innerText屬性的區別例項介紹
- get_attribute ('textContent') 和 get_attribute ('value') 有什麼區別
- JavaScript outerHTMLJavaScriptHTML
- JavaScript textContentJavaScript
- JavaScript innerTextJavaScript
- JavaScript innerHTMLJavaScriptHTML
- innerHTML使用HTML
- 和區別
- ../和./和/的區別
- if …if 和if …else if 區別
- 和 的區別
- as 和 with的區別
- in 和 exists區別
- javascript textContent屬性用法JavaScript
- LinkedList和ArrayList的區別、Vector和ArrayList的區別
- http和https的區別/get和post的區別HTTP
- undefined 和 null 區別?UndefinedNull
- SSL和TLS 區別TLS
- ./ 和sh 的區別
- JQuery this和$(this)的區別jQuery
- jquery $(this) 和this的區別jQuery
- ClassNotFoundException和NoClassDefFoundError區別ExceptionError
- T和?的區別
- SCSS 和 SASS 區別CSS
- null和undefined區別NullUndefined
- url和uri區別
- get和post區別
- ++a和a++的區別
- NoClassDefFoundError和ClassNotFoundException區別ErrorException
- $(":input")和$("input")區別