input number maxlength chrome

<input type=”number” maxlength=2>

上面这个html代码,其实是想限定number的值为小数点后一位,但其实没有实现。在Chrome中这个maxlength会被忽略掉,在IE 11和Edge中最多只能输到小数点(例如1.2)。

正确的做法是用 step

<!DOCTYPE html>
<html>
<body>

<p>Numeric restrictions will apply in the input field:</p>

<form action=”/action_page.php”>
Quantity (between 1 and 5):
<input type=”number” step=0.1 name=”quantity” min=”1” max=”5”>
<input type=”submit”>
</form>

<p><b>Note:</b> type=”number” is not supported in IE9 and earlier.</p>

</body>
</html>

Chrome中的 input number 的 maxlength 会被忽略,其实忽略掉是对的。

MDN input maxlength
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#attr-maxlength

Is there a float input type in HTML5?
https://stackoverflow.com/questions/19011861/is-there-a-float-input-type-in-html5