金额小写转换为大写脚本
1.脚本
<script type="text/jscript"> $(function () { $("#<%=txtFundingEstimatesUpper.ClientID %>").val(ConvertMoney($("#<%=txtFundingEstimates.ClientID %>").val())); //金额变化时转为大写 $("#<%=txtFundingEstimates.ClientID %>").bind("input propertychange", function () { var upperMoney = ConvertMoney($(this).val()); $("#<%=txtFundingEstimatesUpper.ClientID %>").val(upperMoney); }); }); function ConvertMoney(strg) { strg = strg.replace(/,/g, ""); var number = Math.round(strg * 100) / 100; number = number.toString(10).split("."); var a = number[0]; if (a.length > 12) return "数值超出范围!"; var e = "零壹贰叁肆伍陆柒捌玖"; var num1 = ""; var len = a.length - 1; for (var i = 0; i <= len; i++) num1 += e.charAt(parseInt(a.charAt(i))) + [["圆", "万", "亿"][Math.floor((len - i) / 4)], "拾", "佰", "仟"][(len - i) % 4]; if (number.length == 2 && number[1] != "") { var a = number[1]; for (var i = 0; i < a.length; i++) num1 += e.charAt(parseInt(a.charAt(i))) + ["角", "分"][i]; } num1 = num1.replace(/零佰|零拾|零仟|零角/g, "零"); num1 = num1.replace(/零{2,}/g, "零"); num1 = num1.replace(/零(?=圆|万|亿)/g, ""); num1 = num1.replace(/亿万/, "亿"); num1 = num1.replace(/^圆零?/, ""); if (num1 != "" && !/分$/.test(num1)) num1 += "整"; return num1; } </script>
2.页面控件
<table> <tr> <td class="EditBox_TD" width="15%">经费概算<font class="red">*</font></td> <td class="EditBox_TD1" width="35%"> <asp:TextBox ID="txtFundingEstimates" runat="server" Width="80%" data-options="required:true,validType:'money'"></asp:TextBox>元</td> <td class="EditBox_TD" width="15%">大写</td> <td class="EditBox_TD1" width="35%"> <asp:TextBox ID="txtFundingEstimatesUpper" runat="server" Width="80%" ReadOnly="true"></asp:TextBox> </td> </tr> </table>
3.显示效果