利用javascript來轉換GB2312到UNICONDE

來源:互聯網
上載者:User
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 <seasonx@163.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>
文本原型:<br>
  <textarea name="decode" cols="100" rows="10"></textarea>
  <br>
轉碼:<br>
  <textarea name="encode" cols="100" rows="10"></textarea>
  <br>
  <input type="checkbox" name="method" checked> 正向轉換
  <input type=button value=" 確 定 ">
  <input type=reset value=" 清 空 ">
  <input type=button value=" 全 選 ">
</form>



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.