var htmlutil = {
/*1. Implements HTML transcoding */
Htmlencode:function (HTML) {
//1 with a browser internal translator. First, dynamically create a container label element, such as D IV
var temp = document.createelement ("div");
2. Then set the string to be converted to this element of innertext (ie support) or textcontent (Firefox, Google support)
(temp.textcontent! = undefined)? (temp.textcontent = html): (Temp.innertext = html);
//3. Finally returns the InnerHTML of this element, which is a string that has been converted by HTML encoding
var output = temp.innerhtml;
temp = null;
return output;
},
/*2. Implement HTML decoding with the browser internal translator */
Htmldecode:function (text) {
//1. First, dynamically create a container tag element, such as Div
var temp = document.createelement ("div");
//2. Then set the string to be converted to this element's InnerHTML (ie, Firefox, Google support)
temp.innerhtml = text;
3. Finally return this element of the innertext (ie support) or textcontent (Firefox, Google support), that is, the HTML decoded string.
var output = Temp.innertext | | temp.textcontent;
temp = null;
return output;
}
};
Summary: encoded by innerHTML Way, by innertext | | Textcontent mode decoding
HTML encoding and decoding