码迷,mamicode.com
首页 > Web开发 > 详细

js实现小写转大写,js实现数字转人民币

时间:2014-08-23 11:21:31      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:js实现小写转大写   js实现数字转人民币   js实现数字转货币   js数字转换   js编程   

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
 <head>
  <title>小写转大写</title>
  <style type="text/css">
    div { position:absolute;left:lin;top:lin;bottom:lin;right:lin; background-color:#AE57A4; text-align:center;
          width:500px;}
  </style>
  <script type="text/javascript">
      function transformNumber() {
          var nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
          var chins = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
          var money = ["元", "十", "百", "千", "万", "十", "百", "千", "亿", "", "", ""];
          var money1 = ["角", "分"];
          var number = document.getElementById("number").value;
          var numbers = number.split(".")
          var chin = "";
          var chin1 = "";
          for (var i = numbers[0].length; i > 0; i--) {
              var s = numbers[0].charAt(numbers[0].length - i); 
              chin += chins[s] + money[i - 1];
          }
          if (numbers[1] != null) {
              for (var j = 0; j < numbers[1].length; j++) {
                  var b = numbers[1].charAt(j);
                  chin1 += chins[b] + money1[j];
              }
          }
          var china = chin + chin1;
          document.getElementById("newnumber").value = china;
      }
      function clearnumber() {
          document.getElementById("number").value = "";
          document.getElementById("newnumber").value = "";
      }
      function promptMessage() {
          document.getElementById("number").value = "小数点后保留两位小数";
      }
      function clearMessage() {
          document.getElementById("number").value = "";
      }
      window.onload = promptMessage;
  </script>
 </head>
 <body>
   <div><br/><br/>
   <h3>银行钱款转换器</h3><br/><br/><br/><br/>
   <span>请输入需转换金额:</span><input type="text" id="number" onfocus="clearMessage();"><br/><br/>
   <span>转换后的大写金额:</span><input type="text" id="newnumber"/><br/><br/>
   <input type="button" id="transform" value="转换" onclick="transformNumber();" />
   <input type="button" id="clear" value="清零" onclick="clearnumber();">
  </div>
 </body>
</html>

js实现小写转大写,js实现数字转人民币

标签:js实现小写转大写   js实现数字转人民币   js实现数字转货币   js数字转换   js编程   

原文地址:http://blog.csdn.net/y_f123/article/details/38776779

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!