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

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

  

posted @ 2018-05-28 17:58  bigman-bugman  阅读(2584)  评论(0编辑  收藏  举报