JS转换HTML转义符
JS转换HTML转义符 //去掉html标签 function removeHtmlTab(tab) { return tab.replace(/<[^<>]+?>/g,'');//删除所有HTML标签 } //普通字符转换成转意符 function html2Escape(sHtml) { return sHtml.replace(/[<>&"]/g,function(c){return {'<':'<','>':'>','&':'&','"':'"'}[c];}); } //转意符换成普通字符 function escape2Html(str) { var arrEntities={'lt':'<','gt':'>','nbsp':' ','amp':'&','quot':'"'}; return str.replace(/&(lt|gt|nbsp|amp|quot);/ig,function(all,t){return arrEntities[t];}); } // 转成空格 function nbsp2Space(str) { var arrEntities = {'nbsp' : ' '}; return str.replace(/&(nbsp);/ig, function(all, t){return arrEntities[t]}) } //回车转为br标签