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
的错误