欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript實(shí)現(xiàn)unicode與ASCII相互轉(zhuǎn)換的方法

 更新時(shí)間:2015年12月10日 09:25:14   作者:xiaoyan  
這篇文章主要介紹了javascript實(shí)現(xiàn)unicode與ASCII相互轉(zhuǎn)換的方法,涉及JavaScript字符串的遍歷、正則匹配及編碼轉(zhuǎn)換相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了javascript實(shí)現(xiàn)unicode與ASCII相互轉(zhuǎn)換的方法。分享給大家供大家參考,具體如下:

<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Unicode、ASCII相互轉(zhuǎn)換</title>
<script type="text/javascript">
//AsciiToUnicode("中國(guó)");
UnicodeToAscii("&#27979;&#35797;");
//ASCII 轉(zhuǎn)換 Unicode
function AsciiToUnicode(content) {
  result = '';
  for (var i=0; i<content.length; i++)
  result+='&#' + content.charCodeAt(i) + ';';
  alert("ASCII:"+content+"\nUnicode:"+result);
}
//Unicode 轉(zhuǎn)換 ASCII
function UnicodeToAscii(content) {
  var code = content.match(/&#(\d+);/g);
  result= '';
  for (var i=0; i<code.length; i++)
  result += String.fromCharCode(code[i].replace(/[&#;]/g, ''));
  alert("Unicode:"+content+"\nASCII:"+result);
}
</script>
</head>
<body>
</body>
</html>

希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論