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

Xem thảo luận

Show

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.innerText
    3

    x.innerText
    4
    x.innerText
    5
    x.innerText
    6

    x.innerText
    4
    x.innerText
    8
    x.innerText
    6

    x.innerText
    0
    x.innerText
    4
    x.innerText
    2
    x.innerText
    6
    x.innerText
    4
    x.innerText
    5
    x.innerText
    6
    x.innerText
    7
    x.innerText
    0
    x.innerText
    9
    x.innerText
    2
    x.innerText
    6
    x.innerText
    9
    x.innerText
    8
    x.innerText
    6

    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.innerText
    4

    HTML

    x.innerText
    64
    x.innerText
    65

    x.innerHTML
    6
    x.innerHTML
    7
    x.innerText
    4
    x.innerText
    39
    x.innerHTML
    8
    x.innerText
    4
    x.innerText
    30
    x.innerText
    31
    x.innerText
    3030
    x.innerText
    4
    x.innerText
    4
    x.innerText
    48
    x.innerText
    49
    x.innerText
    48
    x.innerText
    51
    x.innerText
    0
    x.innerText
    9
    x.innerText
    36
    x.innerText
    6
    x.innerText
    0
    x.innerText
    4
    x.innerText
    58
    x.innerText
    59
    x.innerText
    58
    x.innerText
    6
    x.innerText
    0
    x.innerText
    4
    x.innerText
    36
    x.innerText
    37
    x.innerText
    4
    x.innerText
    67
    x.innerText
    0
    x.innerText
    9
    x.innerText
    64
    x.innerText
    6
    x.innerText
    4
    x.innerText
    4
    x.innerText
    42
    x.innerText
    43____42
    x.innerText
    4
    x.innerText
    47
    x.innerText
    0
    x.innerText
    9
    x.innerText
    64
    x.innerText
    6
    x.innerText
    0
    x.innerText
    4
    x.innerText
    64
    x.innerText
    65
    x.innerText
    0
    x.innerText
    4
    x.innerText
    60
    x.innerText
    6
    x.innerText
    4
    x.innerText
    63

    x.innerText
    64
    x.innerText
    65

    x.innerText
    64

    x.innerText
    0
    x.innerText
    4
    x.innerText
    64
    x.innerText
    45
    x.innerText
    4
    x.innerText
    69
    x.innerText
    4
    x.innerText
    01

    Output   

    x.innerText
    05
    x.innerText
    4
    x.innerText
    69
    x.innerText
    0
    x.innerText
    9
    x.innerText
    60
    x.innerText
    6
    x.innerText
    9
    x.innerHTML
    6
    x.innerText
    6
    x.innerText
    9
    x.innerText
    5
    x.innerText
    6

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

     

    x.innerText
    64
    x.innerText
    67

     

    ____10

    x.innerText
    4
    x.innerText
    58
    x.innerText
    85
    x.innerText
    58
    x.innerText
    6

     

    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.