html - 为什么类型为 "number"的 html 输入允许在字段中输入字母 'e'?

我有以下 html5 输入元素:

<input type="number">

为什么这个输入允许在输入字段中输入字符“e”?无法输入其他字母字符(如预期的那样)

使用 chrome v. 44.0.2403.107

下面的例子来看看我的意思。

<input type="number">

最佳答案

因为这正是 the spec说它应该工作。输入的数字可以接受floating-point numbers ,包括负号和 eE 字符(其中指数是 eE 之后的数字):

A floating-point number consists of the following parts, in exactly the following order:

  1. Optionally, the first character may be a "-" character.
  2. One or more characters in the range "0—9".
  3. Optionally, the following parts, in exactly the following order:
    1. a "." character
    2. one or more characters in the range "0—9"
  4. Optionally, the following parts, in exactly the following order:
    1. a "e" character or "E" character
    2. optionally, a "-" character or "+" character
    3. One or more characters in the range "0—9".

关于html - 为什么类型为 "number"的 html 输入允许在字段中输入字母 'e'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31706611/

相关文章:

html - 标签中是否需要 ="text/css"类型?

html - 如何更改 Canvas 元素中元素的不透明度(alpha、透明度)?

image - 如何在保持图像纵横比的同时拉伸(stretch)图像以填充

html - 如何防止滚动条覆盖 IE10 中的内容?

html - 将居中文本添加到水平线的中间

html - 如何删除css中的背景图像?

html - XHTML 中所有有效的自闭合元素(由主要浏览器实现)是什么?

javascript - 获取元素的父div

html - 如何在 div 中使按钮居中?

javascript - 如何使用 JavaScript 获取 HTML 页面的标题?