說明:
輸入數字轉成支票格式國字。
原始碼:
<input id="input_num" type="text" size="30" value="" /> <button id="convert_num">Convert</button> <input id="output_num" type="text" size="30" value="" /> <script type="text/javascript"> function $(id) {return document.getElementById(id.substr(1));} $('#output_num').onmouseover = function() { $('#output_num').select(); }; $('#convert_num').onclick = function() { var chnum = "零壹貳參肆伍陸柒捌玖"; var chunit = "拾佰仟"; var chunits = "\r萬億兆京垓秭穰溝澗正載極"; var num = $('#input_num').value?$('#input_num').value:""; var output = ""; var is_zero = true; for(var i=0;i<num.length;i++) { var n = parseInt(num.charAt(i)); if(isNaN(n)) { $('#output_num').value = "Error"; return; } if((num.length-i-1)%4 == 0) { if(n == 0) { if(!is_zero) output += chunits.charAt((num.length-i-1)/4); is_zero = true; } else { output += chnum.charAt(n) + chunits.charAt((num.length-i-1)/4); is_zero = false; } } else if(n != 0) { output += chnum.charAt(n) + chunit.charAt((num.length-i-1)%4-1); is_zero = false; } } $('#output_num').size = output.length*2; $('#output_num').value = (output?output:"零") + "元整"; } </script>