<script type="text/javascript">
var HtmlUtil = {
/*1.用正则表达式实现html转码*/
htmlEncodeByRegExp:function (str){
var s = "";
if(str.length == 0) return "";
s = str.replace(/&/g,"&");
s = s.replace(/</g,"<");
s = s.replace(/>/g,">");
s = s.replace(/ /g," ");
s = s.replace(/\'/g,"'");
s = s.replace(/\"/g,""");
return s;
},
/*2.用正则表达式实现html解码*/
htmlDecodeByRegExp:function (str){
var s = "";
if(str.length == 0) return "";
s = str.replace(/&/g,"&");
s = s.replace(/</g,"<");
s = s.replace(/>/g,">");
s = s.replace(/ /g," ");
s = s.replace(/'/g,"\'");
s = s.replace(/"/g,"\"");
return s;
}
};
</script>
<script type="text/javascript">
var html = "${tratext.text}";
//tratext 为参数传递
var decodeHTML = HtmlUtil.htmlDecodeByRegExp(html);
document.write(decodeHTML);
</script>
文本编辑器html代码<变成& lt;解决
最新推荐文章于 2024-09-22 13:54:50 发布