大文字・小文字・全角・半角変換

  1. <!DOCTYPE html>
  2. <html lang="ja">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>大文字・小文字・全角・半角変換</title>
  6. <body>
  7. <h1>大文字・小文字・全角・半角変換</h1>
  8. <script type="text/javascript">
  9.   // 英数字を半角変換
  10.   function changeHalfChar()
  11.   {
  12.     str = document.getElementById("InputText").value
  13.     
  14.     HalfChar = str.replace(/[A-Za-z0-9]/g, function(s)
  15.     {
  16.       return String.fromCharCode(s.charCodeAt(0) - 0xFEE0);
  17.     });
  18.     
  19.     alert(HalfChar);
  20.   }
  21.   
  22.   // 英数字を全角変換
  23.   function changeFullChar()
  24.   {
  25.     str = document.getElementById("InputText").value
  26.     
  27.     FullChar = str.replace(/[A-Za-z0-9]/g, function(s)
  28.     {
  29.       return String.fromCharCode(s.charCodeAt(0) + 0xFEE0);
  30.     });
  31.     
  32.     alert(FullChar);
  33.   }
  34.   
  35.   // 英語を小文字変換
  36.   function changeLowerChar()
  37.   {
  38.     str = document.getElementById("InputText").value
  39.     
  40.     LowerChar = str.toLowerCase();
  41.     
  42.     alert(LowerChar);
  43.   }
  44.   
  45.   // 英語を大文字変換
  46.   function changeUpperChar()
  47.   {
  48.     str = document.getElementById("InputText").value
  49.     
  50.     UpperChar = str.toUpperCase();
  51.     
  52.     alert(UpperChar);
  53.   }
  54.   
  55. </script>
  56. <input type="text" value="" id="InputText" /><br />
  57. <input type="button" value="英数字を半角変換" onclick="changeHalfChar()" />
  58. <input type="button" value="英数字を全角変換" onclick="changeFullChar()" />
  59. <input type="button" value="英語を小文字変換" onclick="changeLowerChar()" />
  60. <input type="button" value="英語を大文字変換" onclick="changeUpperChar()" />
  61. <div style="font-size:10pt;text-align:right;margin-top:0.5em;">
  62. <a href="//tips.recatnap.info/" target="_top">PCスキルの小技・忘却防止メモ</a> -
  63. <a href="//tips.recatnap.info/wiki/" target="_top">PCスキルの小技・忘却防止メモのまとめ(wiki)</a>
  64. </div>
  65. <div style="font-size:10pt;text-align:center;margin-top:0.5em;padding:0.5em;border-top:1px solid #ccc;">
  66. Copyright &copy; 2009 by PCスキルの小技・忘却防止メモ. All rights reserved.
  67. </div>
  68. </body>
  69. </html>