货币转换
9037 点击·0 回帖
![]() | ![]() | |
![]() | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script src="jquery-1.4.2.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('#keyup').bind('keyup', function(event){ var content; var ketup_con; $ketup_con=$('#keyup').val(); if(isNaN(ketup_con)){ $content=DX($ketup_con); $('#test').text($content); } }); }) </script> <script type="text/javascript"> function DX(n){ if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(n)) return"数据非法"; var unit="千百拾亿千百拾万千百拾元角分",str=""; n += "00"; var p= n.indexOf('.'); if(p >=0) n=n.substring(0,p)+n.substr(p+1,2); unit=unit.substr(unit.length-n.length); for(var i=0; i<n.length; i++) str +='零壹贰叁肆伍陆柒捌玖'.charAt(n.charAt(i))+unit.charAt(i); return str.replace(/零(千|百|拾|角)/g,"零").replace(/(零)+/g,"零").replace(/零(万|亿|元)/g,"$1").replace(/(亿)万|壹(拾)/g, "$1$2").replace(/^元零?|零分/g,"").replace(/元$/g,"元整"); } </script> </head> <body> 测试:<input type="text" id="keyup" /> <span id="test"></span> </body> </html> | |
![]() | ![]() |