Xem thảo luận 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: Chúng ta hãy giả sử rằng chúng ta có một biến JavaScript gọi là x.x.innerText3 x.innerText4 x.innerText5 x.innerText6 x.innerText4 x.innerText8 x.innerText6 x.innerText0 x.innerText4 x.innerText2 x.innerText6 x.innerText4 x.innerText5 x.innerText6 x.innerText7 x.innerText0 x.innerText9 x.innerText2 x.innerText6 x.innerText9 x.innerText8 x.innerText6 Chúng ta hãy giả sử rằng chúng ta có một biến JavaScript gọi là x. Nội tâm x.innerText4HTML x.innerText64 x.innerText65 x.innerHTML6 x.innerHTML7 x.innerText4 x.innerText39 x.innerHTML8 x.innerText4 x.innerText30 x.innerText31 x.innerText3030 x.innerText4 x.innerText4 x.innerText48 x.innerText49 x.innerText48 x.innerText51 x.innerText0 x.innerText9 x.innerText36 x.innerText6 x.innerText0 x.innerText4 x.innerText58 x.innerText59 x.innerText58 x.innerText6 x.innerText0 x.innerText4 x.innerText36 x.innerText37 x.innerText4 x.innerText67 x.innerText0 x.innerText9 x.innerText64 x.innerText6 x.innerText4 x.innerText4 x.innerText42 x.innerText43____42 x.innerText4 x.innerText47 x.innerText0 x.innerText9 x.innerText64 x.innerText6 x.innerText0 x.innerText4 x.innerText64 x.innerText65 x.innerText0 x.innerText4 x.innerText60 x.innerText6 x.innerText4 x.innerText63 x.innerText64 x.innerText65 x.innerText64 x.innerText0 x.innerText4 x.innerText64 x.innerText45 x.innerText4 x.innerText69 x.innerText4 x.innerText01 Output
____10 Differences: Trước khi nhấp vào:innerText 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. 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ì? 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. 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?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. 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?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. |