1. 程式人生 > >input框在輸入後將輸入值格式化為數字

input框在輸入後將輸入值格式化為數字

<input type="text" name="money"  required style="width: 15%" value="0" onblur="onlyNum(this)"  />
<script>
	function onlyNum(that){
        var vv = Math.round(that.value.replace(/[^\d.]/g,"") * 100) /100;
        vv += "";
        if(vv.indexOf(".")>-1){
            that.value = vv;
        }else{
            that.value = vv+".00";
        }
    }
</script>