html编码的转换,&#*; 模式

[ 2016-11-14 11:41:37 | 作者: admin ]
字号: | |
<script>
var htmlEncode=function(str) {//HTML des encode.
         var res=[];
         for(var i=0;i < str.length;i++)
                res[i]=str.charCodeAt(i);
         return "&#"+res.join(";&#")+";";
};
var htmlDecode = function(str) {
         return str.replace(/&#(x)?([^&]{1,5});?/g,function($,$1,$2) {
                return String.fromCharCode(parseInt($2 , $1 ? 16:10));
         });
};
</script>


&#39;&#39;中国&#39;&#39;
转出为
''中国''
[最后修改由 admin, 于 2016-11-14 11:43:56]
评论Feed 评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=2357

这篇日志没有评论。

此日志不可发表评论。