<!-- JS-unicode;编码转换 -->
<script type="text/
javascript">
var toHTML = {
on: function(str) {
var a = [],
i = 0;
for (; i < str.length;) a[i] = str.charCodeAt(i++);
return "&#" + a.join(";&#") + ";"
},
un: function(str) {
return str.replace(/&#(x)?([^&]{1,5});?/g,
function(a, b, c) {
return String.fromCharCode(parseInt(c, b ? 16 : 10))
})
}
};
//alert(toHTML.on(""请输""));
//alert(toHTML.un("大幅"));
</script>
(
脚本学堂 www.jb200.com 编辑整理)
<!-- JS-unicode编码转换。 -->
<script type="text/javascript">
var toUN = {
on: function(str) {
var a = [],
i = 0;
for (;i< str.length;){
a[i] = ("00" + str.charCodeAt(i++).toString(16)).slice( - 4);
}
return "u" + a.join("u")
},
un: function(str) {
return unescape(str.replace(//g, "%"))
}
};
//var b = 'Today is a lice day';
//alert(b.slice(-6,-2));
var a = '"';
alert(a.charCodeAt(0).toString(16).slice(-4));
//alert(toUN.on(""请输""));
//alert(toUN.un("u0022u8BF7u8F93u0022"));
</script>