HTML text escape tips

Time:2021-12-5

Today in CSDN to see a HTML text escape tips, very simple.

1. Use the function of DOM. First pass it to a DOM object as innerText, and then take the innerHTML attribute to get the escaped text.

For example:

div1.innerText = “<h1>title title….</h1>”;

var str = div1.innerHTML; // “&lt;h1&gt;title title…”

2. Assuming that there is a text context, you can perform $(x). Text (context). Html() on a jQuery object $(x), and an escaped text will be returned.

var str = $(x).text(context).html()

Recommended Today

Lecture 05 Intro to SQL (Continued)

Null Values: It is possible for tuples to have a null value, denoted by null, for some of their attributes. null signifies an unknown value or that a value does not exist. The result of any arithmetic expression involving null is null The predicate is null can be used to check for null values.   Null Values and Three Valued Logic: Three values […]