【发布时间】:2020-09-30 13:44:17
【问题描述】:
我想创建一个 input[type=number],它不允许多个小数和所有非数字,包括字母 e。问题是,适用于 input[type=text] 的正则表达式不适用于 input[type=number]。
当我记录到控制台输入多个小数的数字值时,该值为空。
这里是 Codepen: https://codepen.io/btn-ninja/pen/oNxRoJN?editors=1111
HTML
<input type="number"
class="isDecimal"
placeholder="Type 2.3.4 and watch console"
maxlength="20">
JS
$('.isDecimal').on("input", function(e) {
var num = $(this).val().toString();
console.log(num);
});
【问题讨论】: