Hướng dẫn innerhtml vs textcontent - Internalhtml so với nội dung văn bản

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • 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');
    • Đọ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. 
    x.innerText
    • Bên trong và bên trong đều là các thuộc tính của JavaScript. Tuy nhiên, có sự khác biệt trong đó văn bản được xử lý. Hãy để chúng tôi kiểm tra cú pháp của cả hai và sau đó lấy một ví dụ để xem xét sự khác biệt. & NBSP;
    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.innerText4x.innerText5x.innerText6

    x.innerText4x.innerText8x.innerText6

    x.innerText0x.innerText4x.innerText2x.innerText6x.innerText4x.innerText5x.innerText6x.innerText7x.innerText0x.innerText9x.innerText2x.innerText6x.innerText9x.innerText8x.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.innerText4

    HTML

    x.innerText64x.innerText65

    x.innerHTML6 x.innerHTML7x.innerText4x.innerText39x.innerHTML8x.innerText4x.innerText30 x.innerText31x.innerText3030x.innerText4x.innerText4x.innerText48x.innerText49x.innerText48x.innerText51x.innerText0x.innerText9x.innerText36x.innerText6x.innerText0x.innerText4x.innerText58x.innerText59x.innerText58x.innerText6x.innerText0x.innerText4x.innerText36 x.innerText37x.innerText4x.innerText67x.innerText0x.innerText9x.innerText64x.innerText6x.innerText4x.innerText4x.innerText42x.innerText43____42x.innerText4x.innerText47x.innerText0x.innerText9x.innerText64x.innerText6x.innerText0x.innerText4x.innerText64 x.innerText65x.innerText0x.innerText4x.innerText60x.innerText6x.innerText4x.innerText63

    x.innerText64x.innerText65

    x.innerText64

    x.innerText0x.innerText4x.innerText64 x.innerText45x.innerText4x.innerText69x.innerText4x.innerText01

    Output   

    x.innerText05x.innerText4x.innerText69x.innerText0x.innerText9x.innerText60x.innerText6x.innerText9x.innerHTML6x.innerText6x.innerText9x.innerText5x.innerText6

     

    x.innerText64x.innerText67

     

    ____10x.innerText4x.innerText58 x.innerText85x.innerText58x.innerText6

     

    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.

    Chủ đề