<script type="text/javascript">
function utf82unicode(str) {
//var str=document.getElementById('codes').value;
var a = [], i = 0;
for (; i < str.length ;) a[i] = ("00" + str.charCodeAt(i ++).toString(16)).slice(-4);
return "" + a.join("");
//document.getElementById('codes').value="" + a.join("");
}
function on() {
var str=document.getElementById('codes').value;
var a = [], i = 0;
for (; i < str.length ;) a[i] = ("00" + str.charCodeAt(i ++).toString(16)).slice(-4);
//return "\\u" + a.join("\\u");
document.getElementById('codes').value="" + a.join("");
}
function un(str) {
var str=document.getElementById('codes').value;
document.getElementById('codes').value=unescape(str.replace(/\\/g, "%"));
}
function hexToString(){
var val="\u0074\u0065\u0073\u0074";
var str=on(document.getElementById('codes').value);
//var arr = str.split(",");
//for(i = 0; i < arr.length; i++){
// val += arr[i].fromCharCode(i);
//}
//return val;
document.getElementById('codes').value=fromCharCode("0074");
}
</script>
<script type="text/javascript" src="/js/jquery.qqFace.js"></script>
+++++++++++++++++++++++++++++++++++++++++++++
<script Language=Javascript>
var to16 = {
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, "%"));
}
};
</script>
(codes.value)>
(codes.value)>
+++++++++++++++++++++++++++++
http://www.jslab.org.cn/?tag=charset
<script type="text/javascript">
var to16 = {
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 str = to16.on("test");
var str2 = to16.un("\u0074\u0065\u0073\u0074 ");
document.write(str+"
");
document.write(str2+"
");
</script>
+++++++++++++++++++++++++++++++++
http://hanz188.iteye.com/blog/507889
以下代码是我在http://www.94this.com.cn/article/290.htm偶然看到的。想到平常我也经常使用这些功能,于是转载过来,与大家共同分享。
我们在使用struts1.3开发国际化的web应用程序时经常可以用到将汉字转化成UNICODE的功能,以前我是这么做的。在Myeclipse中创建一个javascript脚本文件,比如说example.js。然后在里面输入
window.alert("需要转化的中文");
然后将这些代码全选后,按Ctrl+Shift+F即可将其转化成UNICODE编码。
<script Language=Javascript>
var classObj=
{
ToUnicode:function(str)
{
return escape(str).replace(/%/g,"\\").toLowerCase();
},
UnUnicode:function(str)
{
return unescape(str.replace(/\\/g, "%"));
},
copyingTxt:function(str)
{
document.getElementById(str).select();
document.execCommand("Copy");
}
}
</script>
相关热门文章
给主人留下些什么吧!~~
评论热议