html - 为什么这个数字输入字段不接受逗号

标签 html

我的网站上有一个金额输入字段,但该输入字段不接受逗号。现在的问题是我无法输入 5,21 美元这样的金额。请帮助...一个例子就足够了

Bedrag: <input type="number" name="goed_doel_bedrag" id="goed_doel_bedrag" step="any"min="0" placeholder="Vul hier het bedrag in">

最佳答案

你有:

input type="number"

这会将控件限制为只接受 float 。以下内容来自Mozilla Developer Network

type

The type of control to display. The default type is text, if this attribute is not specified. Possible values are:

  • button: A push button with no default behavior.
  • checkbox: A check box. You must use the value attribute to define the value submitted by this item. Use the checked attribute to indicate whether this item is selected. You can also use the indeterminate attribute to indicate that the checkbox is in an indeterminate state (on most platforms, this draws a horizontal line across the checkbox).
  • color: HTML5 A control for specifying a color. A color picker's UI has no required features other than accepting simple colors as text (more info).
  • date: HTML5 A control for entering a date (year, month, and day, with no time).
  • datetime: HTML5 A control for entering a date and time (hour, minute, second, and fraction of a second) based on UTC time zone.
  • datetime-local: HTML5 A control for entering a date and time, with no time zone.
  • email: HTML5 A field for editing an e-mail address. The input value is validated to contain either the empty string or a single valid e-mail address before submitting. The :valid and :invalid CSS pseudo-classes are applied as appropriate.
  • file: A control that lets the user select a file. Use the accept attribute to define the types of files that the control can select.
  • hidden: A control that is not displayed, but whose value is submitted to the server.
  • image: A graphical submit button. You must use the src attribute to define the source of the image and the alt attribute to define alternative text. You can use the height and width attributes to define the size of the image in pixels.
  • month: HTML5 A control for entering a month and year, with no time zone.
  • number: HTML5 A control for entering a floating point number.
  • password: A single-line text field whose value is obscured. Use the maxlength attribute to specify the maximum length of the value that can be entered.
  • radio: A radio button. You must use the value attribute to define the value submitted by this item. Use the checked attribute to indicate whether this item is selected by default. Radio buttons that have the same value for the name attribute are in the same "radio button group"; only one radio button in a group can be selected at one time.
  • range: HTML5 A control for entering a number whose exact value is not important. This type control uses the following default values if the corresponding attributes are not specified: min: 0, max: 100, value: min + (max-min)/2, or min if max is less than min, step: 1
  • reset: A button that resets the contents of the form to default values.
  • search: HTML5 A single-line text field for entering search strings; line-breaks are automatically removed from the input value.
  • submit: A button that submits the form.
  • tel: HTML5 A control for entering a telephone number; line-breaks are automatically removed from the input value, but no other syntax is enforced. You can use attributes such as pattern and maxlength to restrict values entered in the control. The :valid and :invalid CSS pseudo-classes are applied as appropriate.
  • text: A single-line text field; line-breaks are automatically removed from the input value.
  • time: HTML5 A control for entering a time value with no time zone.
  • url: HTML5 A field for editing a URL. The input value is validated to contain either the empty string or a valid absolute URL before submitting. Line-breaks and leading or trailing whitespace are automatically removed from the input value. You can use attributes such as pattern and maxlength to restrict values entered in the control. The :valid and :invalid CSS pseudo-classes are applied as appropriate.
  • week: HTML5 A control for entering a date consisting of a week-year number and a week number with no time zone.

因为它只接受 float ,所以它不接受像 $123,456(字符串)这样的输入。只需将输入类型更改为 text 即可解决您的问题。

您还可以在控件前面加上您的货币符号,例如 this example from bootstrap :

enter image description here

关于html - 为什么这个数字输入字段不接受逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27702120/

相关文章:

javascript - 如果 div 有 BR 并且没有文本 jQuery,请删除它

javascript - 如何根据选择将按钮发送到背景/禁用它们?

html - 当我切换移动菜单时,标题下方的所有网站内容都被下推。任何想法如何解决这个问题?

html - 如何在列表项周围创建价格标签(如边框)

html - 用表格设计

html - 带衬里的自定义 CSS Angular

jquery - CSS Tab - 在第一次加载时隐藏子内容

jquery - 奇怪的下拉菜单jquery

html - Bootstrap Glyphicons 隐藏边框

html - 在 EDGE 浏览器中跳转到特定的 PDF 页面