js保留小数
<script type="text/javascript"> $(function () { $("#one").change(function () { var numParse = NumParse($(this).val(), 2, "f"); $(this).val(numParse); }); }); function NumParse(val, num, intOrFloat) { if (val == null && val == "" && val == undefined) { val = 0; } if (isNaN(val)) { val = 0; } if (isNaN(val)) { num = 2; } var number = 0; if (intOrFloat == "i") { number = parseInt(val).toFixed(num); } else { number = parseFloat(val).toFixed(num); } return number; } </script> value:<input type="text" id="one">