日出星辰

          數字轉換人民幣大寫

          通過JS完成,能滿足多種瀏覽器,不足之處是展示效果不是很理想,而且最多只能輸入13位數字,希望大家提出改正方法

          <html>
          <head>
          <title>數字轉換人民幣大寫</title>
          <script type="text/javascript">
          function convert() {
          var big = new Array("", "", "", "", "", "", "", "", "", "");
          var unit = new Array("", "", "", "", "", "", "", "", "", "",
          "", "", "");
          var num = document.getElementById("num").value;
          if (num =="") {
          alert(
          "輸入為空,請輸入數字");
          return false;
          }

          if (num.match(/[^,.\d]/) != null) {
          alert(
          "輸入內容不合法,請輸入數字");
          return false;
          }
          var temp = "";
          if (num != null&&num.length<=13) {
          for (var i = 0; i < num.length; i++) {
          if(num.charAt(i)==0){
          alert(
          "輸入內容不合法,不能以0開始");
          return false;
          }
          else{
          temp
          = temp + big[num.charAt(i)] + unit[num.length - i - 1];
          }

          }
          }
          else{
          alert(
          "最多只能輸入13位數字");
          return false;
          }
          document.getElementById(
          "rmb").innerText = temp;

          }


          </script>
          </head>

          <body>
          <input type="text" name="num" id="num"/>
          <input type="button" name="convert" value="轉換" onclick="return convert()"/>
          <input type="text" id="rmb"/>
          </body>
          </html>


           

           

          posted on 2011-10-08 10:36 日出星辰 閱讀(192) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 合作市| 巴彦县| 五寨县| 蒲江县| 宣汉县| 丰镇市| 青神县| 双江| 图木舒克市| 江安县| 深州市| 卢湾区| 永城市| 元阳县| 荃湾区| 铁力市| 江津市| 平顺县| 凌源市| 昔阳县| 临城县| 呼图壁县| 伊金霍洛旗| 新宁县| 梁河县| 遂宁市| 平阴县| 林州市| 赣榆县| 贡嘎县| 光山县| 通化县| 德保县| 南通市| 汉寿县| 柏乡县| 凤城市| 高淳县| 东源县| 宜君县| 莫力|