Js特殊字符转义之htmlEscape()方法

function htmlEscape(text){ 
  return text.replace(/[<>"&]/g, function(match, pos, originalText){
    switch(match){
    case "<": return "<"; 
    case ">":return ">";
    case "&":return "&"; 
    case """:return """; 
  } 
  }); 
}

  

原文地址:https://www.cnblogs.com/bigman-bugman/p/9101450.html