htm escape

String.prototype.escapeHtml = function() {
   var div = document.createElement('div');
   var text = document.createTextNode(this);
   div.appendChild(text);
   return div.innerHTML;
}
String.prototype.htmlEncode = function(){
  return this.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;");
}
String.prototype.htmlDecode = function(){
  return this.replace(/&amp;/g, "&").replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"');
}

var a = "<b>bold</b>";
var b = a.escapeHtml();
var c = a.htmlEncode();
var d = c.htmlDecode();
-------------------------

你可能感兴趣的:(C++,c,prototype,C#)