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>

猜你喜欢

转载自blog.csdn.net/cyzman/article/details/83110279