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

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');
    • 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.innerText
    • Chúng ta hãy giả sử rằng chúng ta có một biến JavaScript gọi là x.
    x.innerHTML

    Example:  

    Nội tâm

    <html>

    <head>

    x.innerText
    0<
    x.innerText
    2>

    x.innerText
    4
    x.innerText
    5

    x.innerText
    6
    x.innerText
    7

    x.innerText
    0
    x.innerText
    9
    x.innerText
    2>

    x.innerText
    9head>

    Nội tâm

    HTML

    <

    x.innerHTML
    6
    x.innerHTML
    7

    x.innerText
    49

    x.innerHTML
    8<0 1030

    x.innerText
    4<<8<9<8html1

    x.innerText
    0
    x.innerText
    96>

    x.innerText
    0<html8html9html8>

    x.innerText
    0<6 7

    x.innerText
    4>7

    x.innerText
    0
    x.innerText
    9>4>

    x.innerText
    4<<2<3____42

    x.innerText
    4<7

    x.innerText
    0
    x.innerText
    9>4>

    x.innerText
    0<>4 >5

    x.innerText
    0<>0>

    x.innerText
    4>3

    >4>5

    x.innerText
    0<>4 <5

    x.innerText
    4>9

    x.innerText
    4
    x.innerText
    01

    >4>5

    >4

    x.innerText
    05

    x.innerText
    4>9

    x.innerText
    0
    x.innerText
    9>0>

    x.innerText
    9
    x.innerHTML
    6>

    x.innerText
    9html>

    Output  

    ____10<html8 head5html8>

      

    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ì?
     

    >4>7

      

    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ì?
     

    Trước khi nhấp vào:

      

    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ì?
     

    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.