Unescape thoát HTML
Bắt đầu nội dung chính
OSCC · JavaScript, Chuỗi, Trình duyệt, Regexp · 22 tháng 10, 2020 Show Các ký tự HTML đã thoát Unescapes
const unescapeHTML = str => str.replace( /&|<|>|'|"/g, tag => ({ '&': '&', '<': '<', '>': '>', ''': "'", '"': '"' }[tag] || tag) ); Đoạn trích được đề xuất
Từ đầu ra ở trên, chúng ta có thể thấy ngoại lệ trong địa chỉ email có ký hiệu đặc biệt “@” không được mã hóa & hiển thị giống như trong đầu vào & phần còn lại của văn bản đã được mã hóa Bây giờ, nếu chúng ta muốn chuyển đổi văn bản được mã hóa, tức là. , bản mã thành văn bản có thể đọc bình thường thì chúng ta phải sử dụng hàm unescape() sẽ giải mã văn bản được mã hóa. Giải mã là quá trình chuyển đổi bản mã thành văn bản thuần túy. 2. hàm unescape(). Hàm này lấy một chuỗi làm tham số duy nhất và sử dụng nó để giải mã chuỗi đó được mã hóa bởi hàm escape(). Chuỗi thập lục phân trong chuỗi được thay thế bằng các ký tự mà chúng đại diện khi được giải mã thông qua hàm unescape() cú pháp unescape(string) Thông số. Chức năng này chấp nhận một tham số duy nhất
Giá trị trả về. Trả về một chuỗi đã giải mã Ghi chú. Chức năng này chỉ giải mã các ký tự đặc biệt, chức năng này không được dùng nữa ngoại lệ. @ – +. / * _ ví dụ 1. Trong ví dụ này, chúng tôi đã sử dụng ký tự đặc biệt để xem các thay đổi. JavascriptGeeks for Geeks!!! To contribute articles contact us at [email protected]7 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks for Geeks!!! To contribute articles contact us at [email protected]9 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks for Geeks!!! To contribute articles contact us at [email protected]5 Geeks for Geeks!!! To contribute articles contact us at [email protected]6 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org1 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org4____45 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org6 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org9 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 unescape(string)1 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks for Geeks!!! To contribute articles contact us at [email protected]5 Geeks for Geeks!!! To contribute articles contact us at [email protected]70 unescape(string)5 ________ 372 ________ 373 ________ 41 unescape(string)9 Geeks for Geeks!!! To contribute articles contact us at [email protected]72 đầu ra Geeks for Geeks!!! To contribute articles contact us at [email protected] Từ ví dụ trên, chúng ta có thể thấy bản mã được giải mã thành văn bản thuần túy bằng cách sử dụng hàm unescape() ví dụ 2. JavascriptGeeks for Geeks!!! To contribute articles contact us at [email protected]7 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks for Geeks!!! To contribute articles contact us at [email protected]9 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks for Geeks!!! To contribute articles contact us at [email protected]81 Geeks for Geeks!!! To contribute articles contact us at [email protected]82 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org0 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org6 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org4____387 Geeks for Geeks!!! To contribute articles contact us at [email protected]88 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks for Geeks!!! To contribute articles contact us at [email protected]91 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org4____45 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org6 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks for Geeks!!! To contribute articles contact us at [email protected]98 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org4____381 Geeks for Geeks!!! To contribute articles contact us at [email protected]82 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks for Geeks!!! To contribute articles contact us at [email protected]91 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org4____388 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org6 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org72 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org74 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks for Geeks!!! To contribute articles contact us at [email protected]82 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org77 unescape(string)5 Geeks for Geeks!!! To contribute articles contact us at [email protected]72 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org00 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org01 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org4____387 Geeks for Geeks!!! To contribute articles contact us at [email protected]88 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks for Geeks!!! To contribute articles contact us at [email protected]91 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org4____45 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org6 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks for Geeks!!! To contribute articles contact us at [email protected]98 Geeks for Geeks!!! To contribute articles contact us at [email protected]8 Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org4____381 Geeks for Geeks!!! To contribute articles contact us at [email protected]82 unescape(string)9 đầu ra Geeks for Geeks!!! To contribute articles contact us at [email protected]3 Sự khác biệt giữa hàm thoát () và thoát () không thoát()thoát khỏi()1Hàm unescape() được sử dụng để giải mã chuỗi được mã hóa bởi hàm escape() Hàm escape() trong JavaScript được sử dụng để mã hóa một chuỗi. Sử dụng hỗ trợ ký tự ASCII, nó tạo ra một chuỗi di động để nó có thể được truyền qua bất kỳ mạng nào tới bất kỳ máy tính nào HTML thoát unescape là gì?Html. html. unescape() thay thế tên thực thể hoặc số thực thể của các ký tự HTML dành riêng bằng biểu diễn ký tự ban đầu . Ví dụ, chuỗi
Hàm unescape() và escape() là gì?Hàm escape() được sử dụng để mã hóa một chuỗi, đảm bảo an toàn khi sử dụng trong URL. Hàm unescape() dùng để giải mã một chuỗi mã hóa .
Có ký tự thoát trong HTML không?Trong HTML, XHTML hoặc XML, bạn có thể sử dụng ký tự thoát để thể hiện bất kỳ ký tự Unicode nào chỉ bằng các chữ cái ASCII . Thoát ký tự được sử dụng trong đánh dấu bao gồm tham chiếu ký tự số (NCR) và tham chiếu ký tự được đặt tên. Tham chiếu ký tự số ở định dạng thập lục phân.
Những ký tự nào phải được thoát trong HTML?Nếu các thuộc tính HTML không được trích dẫn, thì một số ký tự nhất định, quan trọng nhất là khoảng trắng, chẳng hạn như dấu cách và tab , phải được thoát bằng các thực thể. |