找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 17226|回复: 1

[转载代码] hta 实现的字符编码速查

[复制链接]
发表于 2014-8-17 17:23:37 | 显示全部楼层 |阅读模式
代码为转载
作范例不错,功能也比较实用
  1. <!DOCTYPE html>
  2. <!-- saved from url=(0006)about: -->
  3. <!--  vim:set tabstop=4 shiftwidth=4 : -->
  4. <html>
  5. <head>
  6. <hta:application innerborder=0 scroll=0 selection=0 />
  7. <meta http-equiv=content-type content='charset=gb2312' />
  8. <meta http-equiv=msthemecompatible content=yes />
  9. <title>字符编码GBK和Unicode</title>
  10. <style>
  11. span{font:14px bold verdana;color:green;}
  12. textarea {width:100%;height:100px;}
  13. .decorate {border:1px solid #C7E2F1;padding:2px 4px;font:12px consolas;display:inline;float:right;}
  14. .decorate input {width:50px;}
  15. .ps {font:12px consolas;color:#6A5ACD;}
  16. /*label {margin-top:-19px;position:relative;vertical-align:top;padding-top:8px;}*/
  17. label {display:inline-block;height:19px;}

  18. .signature {color:green;text-align:right;position:absolute;bottom:5px;right:20px;font:14px/20px consolas,verdana,宋体;}
  19. .signature A:hover {color:red;}
  20. </style>
  21. <script language="JavaScript">
  22.        
  23. var blue='blue',red='red',green='green',black='black',gray='gray';
  24. Object.prototype.echo=function(c){document.write(this.toString().fontcolor(c||'black')+'<br>')};
  25. String.prototype.Echo=function(c){document.write(('<xmp>'+this.toString()+'</xmp>').fontcolor(c||'black'))};
  26. function $(d){return document.getElementById(d);}
  27. document.onkeydown=function(){
  28.         var ESC=27;
  29.         switch(event.keyCode){
  30.                 case ESC: window.close();break;
  31.         }
  32. }
  33. Array.prototype.format=function(prefix,suffix,delimit){
  34.         return prefix+this.join(suffix+delimit+prefix)+suffix;
  35. }
  36. </script>
  37. </head>

  38. <script language="vbs">
  39. Function GBK(ch)       
  40.         GBK = Hex(Asc(ch))
  41. End Function

  42. Function Unicode(ch)       
  43.         Unicode = Hex(AscW(ch))
  44. End Function
  45. </script>
  46. <body>

  47. <textarea id=input >我是谁?</textarea><br><br>
  48. <div class=decorate>
  49.         前缀:<input name=detect data=prefix1 >
  50.         后缀:<input name=detect data=suffix1 >
  51.         分隔:<input name=detect data=delimit1 value=, >
  52.         <label for=Hex1>Hex:<input id=Hex1 type=checkbox checked=true ></label>
  53. </div>
  54. <span>GBK:</span>
  55. <br>
  56. <textarea id=out1></textarea> <br>

  57. <div class=decorate>
  58.         前缀:<input name=detect data=prefix2 >
  59.         后缀:<input name=detect data=suffix2 >
  60.         分隔:<input name=detect data=delimit2 value=, >
  61.         <label for=Hex2>Hex:<input id=Hex2 type=checkbox checked=true ></label>
  62. </div>
  63. <span>Unicode:</span><br>
  64. <textarea id=out2></textarea>
  65. <div class=ps>
  66.         注: <a href=# onclick=ALT() title="按住alt键,同时按小键盘的数字,即可打出对应的字符">Alt+Num</a> 是十进制GBK<br>
  67.           <a href=# onclick=HTM(0) title="写在html源文件里面,显示出来会是对应的字符">html中&#+Num</a> 是十进制Unicode,也可以是<a href=# onclick=HTM(1)>x+十六进制</a>,
  68. </div>
  69. <script type="text/javascript">
  70.         resizeTo(550,510);
  71. var prefix1='',suffix1='',delimit1='',hex1=0,
  72.         prefix2='',suffix2='',delimit2='',hex2=0;
  73. var arr1=[],arr2=[];
  74. input.onpropertychange=function change(x){
  75.         if(input.value=="")return;
  76.         var str=input.value;arr1=[],arr2=[];
  77.         for(var i=0;i<input.value.length;i++){
  78.                 arr1.push(GBK(str.substr(i,1)));
  79.                 arr2.push(Unicode(str.substr(i,1)));
  80.                 if(!hex1)arr1[i]=parseInt(arr1[i],16);
  81.                 if(!hex2)arr2[i]=parseInt(arr2[i],16);
  82.         }
  83.         if(x!=2)out1.value=arr1.format(prefix1,suffix1,delimit1);
  84.         if(x!=1)out2.value=arr2.format(prefix2,suffix2,delimit2);
  85. }
  86. function changeHex(){
  87.         if(this.id.indexOf('1')>-1){
  88.                 hex1=this.checked;
  89.                 change(1);
  90.         }else{
  91.                 hex2=this.checked;
  92.                 change(2);
  93.         }
  94. }
  95. function changeDecorate(){
  96.         //alert(this.data+'="'+this.value+'";');
  97.         eval(this.data+'="'+this.value+'";');
  98.         if(this.data.indexOf('1')>-1){
  99.                 out1.value=arr1.format(prefix1,suffix1,delimit1);
  100.         }else{
  101.                 out2.value=arr2.format(prefix2,suffix2,delimit2);
  102.         }
  103.        
  104. }
  105. Hex1.onpropertychange=changeHex;
  106. Hex2.onpropertychange=changeHex;
  107. var detects=document.getElementsByName("detect");
  108. //alert(detects.length);
  109. for(var i=0;i<detects.length;i++){
  110.         //detects[i].value=i;
  111.         detects[i].onpropertychange=changeDecorate;
  112. }
  113. function HTM(hex){
  114.         Hex2.checked=hex;
  115.         out2.value=arr2.format(hex?'&#x':'&#',';','');
  116. }
  117. function ALT(){
  118.         Hex1.checked=false;
  119.         out1.value=arr1.format('','',',');
  120. }
  121. input.focus();


  122. //var a=[1,2,3];
  123. //a.format('S','E',',').echo();
  124. </script>

  125. <div class="signature"><a href="http://hi.baidu.com/%E6%84%9A%E4%BA%BA%E9%99%88/">yurenchen</a> 2012/2/3</div>       
  126. </div>
  127. </body>
  128. </html>
复制代码
 楼主| 发表于 2014-8-17 19:42:25 | 显示全部楼层
貌似是从愚人陈的空间里弄来的,不知道他是不是自己写的...
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 01:33 , Processed in 0.018890 second(s), 9 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表