利用javascript来转换GB2312到UNICONDE

80酷酷网    80kuku.com

  javascript|转换

利用javascript来转换

<style>
BODY {
FONT-SIZE: 9pt; PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px;
}
input {
FONT-SIZE: 9pt; height: 13pt;
}
</style>

<script language="JavaScript1.2">
/*
This following code are designed and writen by Windy_sk <seasonx163.net>
You can use it freely, but u must held all the copyright items!
*/

function Str2Unicode(str){
var arr = new Array();
for(var i=0;i<str.length;i++){
  arr[i]="&#" + str.charCodeAt(i) + ";";
}
return(arr.toString().replace(/,/g,""));
}

function Unicode2oStr(str){
var re=/&#[\da-fA-F]{1,5};/ig;
var arr=str.match(re);
if(arr==null)return("");
for(var i=0;i<arr.length;i++){
  arr[i]=String.fromCharCode(arr[i].replace(/[&#;]/g,""));
}
return(arr.toString().replace(/,/g,""))
}

function modi_str(){
if(document.all.text.method.checked){
  if(document.all.text.decode.value!=""){
   document.all.text.encode.value = Str2Unicode(document.all.text.decode.value);
  }else{
   document.all.text.decode.value = Unicode2oStr(document.all.text.encode.value);
  }
}else{
  if(document.all.text.encode.value!=""){
   document.all.text.decode.value = Unicode2oStr(document.all.text.encode.value);
  }else{
   document.all.text.encode.value = Str2Unicode(document.all.text.decode.value);
  }
}
}
</script>
<title>Unicode</title>
<form name=text>
文本原型:

  <textarea name="decode" cols="100" rows="10"></textarea>
 

转换代码:

  <textarea name="encode" cols="100" rows="10"></textarea>
 

  <input type="checkbox" name="method" checked> 正向转换
  <input type=button value=" 确 定 ">
  <input type=reset value=" 清 空 ">
  <input type=button value=" 全 选 ">
</form>



分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: