Board logo

标题: [转载代码] hta 实现的字符编码速查 [打印本页]

作者: CrLf    时间: 2014-8-17 17:23     标题: hta 实现的字符编码速查

代码为转载
作范例不错,功能也比较实用
  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. var blue='blue',red='red',green='green',black='black',gray='gray';
  23. Object.prototype.echo=function(c){document.write(this.toString().fontcolor(c||'black')+'<br>')};
  24. String.prototype.Echo=function(c){document.write(('<xmp>'+this.toString()+'</xmp>').fontcolor(c||'black'))};
  25. function $(d){return document.getElementById(d);}
  26. document.onkeydown=function(){
  27. var ESC=27;
  28. switch(event.keyCode){
  29. case ESC: window.close();break;
  30. }
  31. }
  32. Array.prototype.format=function(prefix,suffix,delimit){
  33. return prefix+this.join(suffix+delimit+prefix)+suffix;
  34. }
  35. </script>
  36. </head>
  37. <script language="vbs">
  38. Function GBK(ch)
  39. GBK = Hex(Asc(ch))
  40. End Function
  41. Function Unicode(ch)
  42. Unicode = Hex(AscW(ch))
  43. End Function
  44. </script>
  45. <body>
  46. <textarea id=input >我是谁?</textarea><br><br>
  47. <div class=decorate>
  48. 前缀:<input name=detect data=prefix1 >
  49. 后缀:<input name=detect data=suffix1 >
  50. 分隔:<input name=detect data=delimit1 value=, >
  51. <label for=Hex1>Hex:<input id=Hex1 type=checkbox checked=true ></label>
  52. </div>
  53. <span>GBK:</span>
  54. <br>
  55. <textarea id=out1></textarea> <br>
  56. <div class=decorate>
  57. 前缀:<input name=detect data=prefix2 >
  58. 后缀:<input name=detect data=suffix2 >
  59. 分隔:<input name=detect data=delimit2 value=, >
  60. <label for=Hex2>Hex:<input id=Hex2 type=checkbox checked=true ></label>
  61. </div>
  62. <span>Unicode:</span><br>
  63. <textarea id=out2></textarea>
  64. <div class=ps>
  65. 注: <a href=# onclick=ALT() title="按住alt键,同时按小键盘的数字,即可打出对应的字符">Alt+Num</a> 是十进制GBK<br>
  66.   <a href=# onclick=HTM(0) title="写在html源文件里面,显示出来会是对应的字符">html中&#+Num</a> 是十进制Unicode,也可以是<a href=# onclick=HTM(1)>x+十六进制</a>,
  67. </div>
  68. <script type="text/javascript">
  69. resizeTo(550,510);
  70. var prefix1='',suffix1='',delimit1='',hex1=0,
  71. prefix2='',suffix2='',delimit2='',hex2=0;
  72. var arr1=[],arr2=[];
  73. input.onpropertychange=function change(x){
  74. if(input.value=="")return;
  75. var str=input.value;arr1=[],arr2=[];
  76. for(var i=0;i<input.value.length;i++){
  77. arr1.push(GBK(str.substr(i,1)));
  78. arr2.push(Unicode(str.substr(i,1)));
  79. if(!hex1)arr1[i]=parseInt(arr1[i],16);
  80. if(!hex2)arr2[i]=parseInt(arr2[i],16);
  81. }
  82. if(x!=2)out1.value=arr1.format(prefix1,suffix1,delimit1);
  83. if(x!=1)out2.value=arr2.format(prefix2,suffix2,delimit2);
  84. }
  85. function changeHex(){
  86. if(this.id.indexOf('1')>-1){
  87. hex1=this.checked;
  88. change(1);
  89. }else{
  90. hex2=this.checked;
  91. change(2);
  92. }
  93. }
  94. function changeDecorate(){
  95. //alert(this.data+'="'+this.value+'";');
  96. eval(this.data+'="'+this.value+'";');
  97. if(this.data.indexOf('1')>-1){
  98. out1.value=arr1.format(prefix1,suffix1,delimit1);
  99. }else{
  100. out2.value=arr2.format(prefix2,suffix2,delimit2);
  101. }
  102. }
  103. Hex1.onpropertychange=changeHex;
  104. Hex2.onpropertychange=changeHex;
  105. var detects=document.getElementsByName("detect");
  106. //alert(detects.length);
  107. for(var i=0;i<detects.length;i++){
  108. //detects[i].value=i;
  109. detects[i].onpropertychange=changeDecorate;
  110. }
  111. function HTM(hex){
  112. Hex2.checked=hex;
  113. out2.value=arr2.format(hex?'&#x':'&#',';','');
  114. }
  115. function ALT(){
  116. Hex1.checked=false;
  117. out1.value=arr1.format('','',',');
  118. }
  119. input.focus();
  120. //var a=[1,2,3];
  121. //a.format('S','E',',').echo();
  122. </script>
  123. <div class="signature"><a href="http://hi.baidu.com/%E6%84%9A%E4%BA%BA%E9%99%88/">yurenchen</a> 2012/2/3</div>
  124. </div>
  125. </body>
  126. </html>
复制代码

作者: CrLf    时间: 2014-8-17 19:42

貌似是从愚人陈的空间里弄来的,不知道他是不是自己写的...




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2