日出星辰

          數字轉換人民幣大寫

          通過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 日出星辰 閱讀(188) 評論(0)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 太湖县| 汪清县| 肥乡县| 紫金县| 磐安县| 吉水县| 哈巴河县| 呈贡县| 上犹县| 綦江县| 温泉县| 隆化县| 永修县| 沂南县| 罗定市| 瓮安县| 隆回县| 思南县| 噶尔县| 峡江县| 五寨县| 镇原县| 南乐县| 建平县| 兴隆县| 江油市| 海晏县| 石狮市| 贵德县| 莱西市| 沙河市| 东阳市| 丽江市| 图木舒克市| 白河县| 临猗县| 四平市| 公主岭市| 新丰县| 阜新市| 昌邑市|