| <!DOCTYPE html> |
| |
| |
| <html> |
| <head> |
| <hta:application innerborder=0 scroll=0 selection=0 /> |
| <meta http-equiv=content-type content='charset=gb2312' /> |
| <meta http-equiv=msthemecompatible content=yes /> |
| <title>字符编码GBK和Unicode</title> |
| <style> |
| span{font:14px bold verdana;color:green;} |
| textarea {width:100%;height:100px;} |
| .decorate {border:1px solid #C7E2F1;padding:2px 4px;font:12px consolas;display:inline;float:right;} |
| .decorate input {width:50px;} |
| .ps {font:12px consolas;color:#6A5ACD;} |
| |
| label {display:inline-block;height:19px;} |
| |
| .signature {color:green;text-align:right;position:absolute;bottom:5px;right:20px;font:14px/20px consolas,verdana,宋体;} |
| .signature A:hover {color:red;} |
| </style> |
| <script language="JavaScript"> |
| |
| var blue='blue',red='red',green='green',black='black',gray='gray'; |
| Object.prototype.echo=function(c){document.write(this.toString().fontcolor(c||'black')+'<br>')}; |
| String.prototype.Echo=function(c){document.write(('<xmp>'+this.toString()+'</xmp>').fontcolor(c||'black'))}; |
| function $(d){return document.getElementById(d);} |
| document.onkeydown=function(){ |
| var ESC=27; |
| switch(event.keyCode){ |
| case ESC: window.close();break; |
| } |
| } |
| Array.prototype.format=function(prefix,suffix,delimit){ |
| return prefix+this.join(suffix+delimit+prefix)+suffix; |
| } |
| </script> |
| </head> |
| |
| <script language="vbs"> |
| Function GBK(ch) |
| GBK = Hex(Asc(ch)) |
| End Function |
| |
| Function Unicode(ch) |
| Unicode = Hex(AscW(ch)) |
| End Function |
| </script> |
| <body> |
| |
| <textarea id=input >我是谁?</textarea><br><br> |
| <div class=decorate> |
| 前缀:<input name=detect data=prefix1 > |
| 后缀:<input name=detect data=suffix1 > |
| 分隔:<input name=detect data=delimit1 value=, > |
| <label for=Hex1>Hex:<input id=Hex1 type=checkbox checked=true ></label> |
| </div> |
| <span>GBK:</span> |
| <br> |
| <textarea id=out1></textarea> <br> |
| |
| <div class=decorate> |
| 前缀:<input name=detect data=prefix2 > |
| 后缀:<input name=detect data=suffix2 > |
| 分隔:<input name=detect data=delimit2 value=, > |
| <label for=Hex2>Hex:<input id=Hex2 type=checkbox checked=true ></label> |
| </div> |
| <span>Unicode:</span><br> |
| <textarea id=out2></textarea> |
| <div class=ps> |
| 注: <a href=# onclick=ALT() title="按住alt键,同时按小键盘的数字,即可打出对应的字符">Alt+Num</a> 是十进制GBK<br> |
| <a href=# onclick=HTM(0) title="写在html源文件里面,显示出来会是对应的字符">html中&#+Num</a> 是十进制Unicode,也可以是<a href=# onclick=HTM(1)>x+十六进制</a>, |
| </div> |
| <script type="text/javascript"> |
| resizeTo(550,510); |
| var prefix1='',suffix1='',delimit1='',hex1=0, |
| prefix2='',suffix2='',delimit2='',hex2=0; |
| var arr1=[],arr2=[]; |
| input.onpropertychange=function change(x){ |
| if(input.value=="")return; |
| var str=input.value;arr1=[],arr2=[]; |
| for(var i=0;i<input.value.length;i++){ |
| arr1.push(GBK(str.substr(i,1))); |
| arr2.push(Unicode(str.substr(i,1))); |
| if(!hex1)arr1[i]=parseInt(arr1[i],16); |
| if(!hex2)arr2[i]=parseInt(arr2[i],16); |
| } |
| if(x!=2)out1.value=arr1.format(prefix1,suffix1,delimit1); |
| if(x!=1)out2.value=arr2.format(prefix2,suffix2,delimit2); |
| } |
| function changeHex(){ |
| if(this.id.indexOf('1')>-1){ |
| hex1=this.checked; |
| change(1); |
| }else{ |
| hex2=this.checked; |
| change(2); |
| } |
| } |
| function changeDecorate(){ |
| |
| eval(this.data+'="'+this.value+'";'); |
| if(this.data.indexOf('1')>-1){ |
| out1.value=arr1.format(prefix1,suffix1,delimit1); |
| }else{ |
| out2.value=arr2.format(prefix2,suffix2,delimit2); |
| } |
| |
| } |
| Hex1.onpropertychange=changeHex; |
| Hex2.onpropertychange=changeHex; |
| var detects=document.getElementsByName("detect"); |
| |
| for(var i=0;i<detects.length;i++){ |
| |
| detects[i].onpropertychange=changeDecorate; |
| } |
| function HTM(hex){ |
| Hex2.checked=hex; |
| out2.value=arr2.format(hex?'&#x':'&#',';',''); |
| } |
| function ALT(){ |
| Hex1.checked=false; |
| out1.value=arr1.format('','',','); |
| } |
| input.focus(); |
| |
| |
| |
| |
| </script> |
| |
| <div class="signature"><a href="http://hi.baidu.com/%E6%84%9A%E4%BA%BA%E9%99%88/">yurenchen</a> 2012/2/3</div> |
| </div> |
| </body> |
| </html>COPY |