Hướng dẫn what is the difference between innerhtml innertext and textcontent? - Sự khác biệt giữa innerhtml innertext và textcontent là gì?
Xem thảo luận Show Cải thiện bài viết Lưu bài viết Xem thảo luận Cải thiện bài viết Lưu bài viết Đọc and innerHTML are both properties of JavaScript. However, there are differences in which the text is handled. Let us check the syntax of the two and then take an example to look at the differences. Syntax: Bàn luận var x = document.getElementById('test');
x.innerText
x.innerHTML Example: Nội tâm
x.innerText0 < x.innerText2 > x.innerText4 x.innerText5 x.innerText6 x.innerText7 x.innerText0 x.innerText9 x.innerText2 > x.innerText9 head > Nội tâm HTML
x.innerHTML6 x.innerHTML7 x.innerText4 9x.innerHTML8 < 0 1 030x.innerText4 < < 8< 9< 8html 1x.innerText0 x.innerText9 6> x.innerText0 < html 8html 9html 8> x.innerText0 < 6 7x.innerText4 > 7x.innerText0 x.innerText9 > 4> x.innerText4 < < 2< 3____42x.innerText4 < 7x.innerText0 x.innerText9 > 4> x.innerText0 < > 4 > 5x.innerText0 < > 0> x.innerText4 > 3
x.innerText0 < > 4 < 5x.innerText4 > 9x.innerText4 x.innerText01
x.innerText05 x.innerText4 > 9x.innerText0 x.innerText9 > 0> x.innerText9 x.innerHTML6 > x.innerText9 html > Output ____10
Trước khi nhấp vào:
Differences: Sau khi nhấp vào bên tronginnerText property sets or returns the text content as plain text of the specified node, and all its descendants whereas the innerHTML property gets and sets the plain text or HTML contents in the elements. Unlike innerText, inner HTML lets you work with HTML rich text and doesn’t automatically encode and decode text. Sự khác biệt giữa Innertext và TextContent là gì?TextContent có được nội dung của tất cả các yếu tố, bao gồm và các yếu tố. Tương phản, bên trong chỉ hiển thị các yếu tố "có thể đọc được" của con người. TextContent Trả về mọi phần tử trong nút. Ngược lại, bên trong nhận thức được kiểu dáng và sẽ không trả lại văn bản của các yếu tố "ẩn". In contrast, innerText only shows "human-readable" elements. textContent returns every element in the node. In contrast, innerText is aware of styling and won't return the text of "hidden" elements.
Cái nào tốt hơn bên trong hoặc textContent?LƯU Ý: Không giống như InsideHTML, TextContent có hiệu suất tốt hơn vì giá trị của nó không được phân tích cú pháp là HTML. Vì lý do đó, sử dụng TextContent cũng có thể ngăn chặn các cuộc tấn công tập lệnh chéo trang (XSS). Không giống như InnerText, TextContent không biết về kiểu dáng CSS và sẽ không kích hoạt phản xạ.textContent has better performance because its value is not parsed as HTML. For that reason, using textContent can also prevent Cross-Site Scripting (XSS) attacks. Unlike innerText, textContent isn't aware of CSS styling and will not trigger a reflow.
Cái nào tốt hơn bên trong hoặc bên trong?InnerText và InsideHtml là các thuộc tính của JavaScript.... khác biệt giữa bên trong và bên trong và bên trong .. Tôi nên sử dụng TextContent hay InternalHtml?Vì lý do này, việc sử dụng InternalHTML không được khuyến nghị khi chèn văn bản thuần túy, thay vào đó hãy sử dụng TextContent.Thuộc tính TextContent sẽ không hiểu rằng mã bạn vượt qua là cú pháp HTML, nhưng chỉ là một văn bản 100% không hơn và không kém.using innerHTML is not recommended when inserting plain text, instead use textContent . The textContent property will not understand that the code you pass is an HTML syntax, but just a 100% text no more and no less. |