输入框限制输入两位小数
为什么80%的码农都做不了架构师?>>>
HTML:
<input type="number" name="price" min="0" step=".01" onchange="setTwoNumberDecimal(this)">
JS:
function setTwoNumberDecimal(that) {
var n = parseFloat(that.value);
that.value = n.toFixed(2)
}
如果没有在调用函数时加上this参数 在函数使用里使用 $(this).val() 会出现
Cannot read property 'toLowerCase' of undefined
的错误
转载于//my.oschina.net/geomen/blog/3042961
还没有评论,来说两句吧...