日出星辰

          數字轉換人民幣大寫

          通過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)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 内黄县| 隆昌县| 阿克| 武穴市| 青铜峡市| 德州市| 合肥市| 兴仁县| 东台市| 华蓥市| 伽师县| 龙井市| 偃师市| 台湾省| 北海市| 洞口县| 拉萨市| 白水县| 甘谷县| 通榆县| 衡水市| 盐池县| 康定县| 登封市| 海伦市| 陆良县| 攀枝花市| 深圳市| 扶余县| 自贡市| 新郑市| 临潭县| 平原县| 嫩江县| 安岳县| 昭苏县| 松原市| 隆回县| 镇平县| 思茅市| 疏勒县|