HTML text escape tips

HTML text escape tips
Today I saw a little trick for HTML text escaping on CSDN, which is very simple.

1. Use dom functions. First pass it to a DOM object as innerTEXT, 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 there is a text context, you can perform $(x).text(context).html() on a jQuery object $(x), which will return an escaped text.

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

<<:  The difference between docker run and start

>>:  How to use the EXPLAIN command in SQL

Recommend

Centos7 installation and configuration of Mysql5.7

Step 1: Get the MySQL YUM source Go to the MySQL ...

Vue.js implements image switching function

This article shares the specific code of Vue.js t...

Understanding and application of JavaScript ES6 destructuring operator

Table of contents Preface The role of deconstruct...

Ubuntu MySQL version upgraded to 5.7

A few days ago, the library said that the server ...

How to use macros in JavaScript

In languages, macros are often used to implement ...

Function overloading in TypeScript

Table of contents 1. Function signature 2. Functi...

MySQL 5.7.17 installation graphic tutorial (windows)

I recently started learning database, and I feel ...

WeChat applet implements fixed header and list table components

Table of contents need: Function Points Rendering...

Summary of problems encountered in the implementation of Vue plug-ins

Table of contents Scene Introduction Plugin Imple...

CentOS 6.5 i386 installation MySQL 5.7.18 detailed tutorial

Most people compile MySQL and put it in the syste...

Implementation and optimization of MySql subquery IN

Table of contents Why is IN slow? Which is faster...

Use CSS to achieve circular wave effect

I often see some circular wave graphics on mobile...

Enable sshd operation in docker

First, install openssh-server in docker. After th...