输入框限制输入两位小数

我不是女神ヾ 2022-01-15 10:19 419阅读 0赞

为什么80%的码农都做不了架构师?>>> hot3.png

HTML:

  1. <input type="number" name="price" min="0" step=".01" onchange="setTwoNumberDecimal(this)">

JS:

  1. function setTwoNumberDecimal(that) {
  2. var n = parseFloat(that.value);
  3. that.value = n.toFixed(2)
  4. }

如果没有在调用函数时加上this参数 在函数使用里使用 $(this).val() 会出现

  1. Cannot read property 'toLowerCase' of undefined

的错误

转载于:https://my.oschina.net/geomen/blog/3042961

发表评论

表情:
评论列表 (有 0 条评论,419人围观)

还没有评论,来说两句吧...

相关阅读

    相关 输入限制

    Web 前端项目,经常会遇到输入控件只能输入汉字,字母或者数字等等,本文介绍了一种简单的方法。比如只能输入字母,则在你输入的时候进行判断,如果你输入的是数字,则会把数字自动的替