js中特殊转换字符为html标签

function htmlEncode(text){

return text.replace(/&/g,'&amp').replace(/\"/g,'&quot').replace(/</g,'&lt').replace(/>/g,'&gt');

}

 

posted @ 2018-04-25 20:02  ppjj  阅读(1937)  评论(0编辑  收藏  举报