LinMinquan's Blog

Experience technology to change life

input number maxlength chrome

<input type="number" maxlength=2>

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

正确的做法是用 step

<!DOCTYPE html>

<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">

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


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

MDN input maxlength

Is there a float input type in HTML5?