我有一个 <input type="number">,我想将用户的输入限制为纯数字或小数点后两位小数.
I have a <input type="number"> and I want to restrict the input of the users to purely numbers or numbers with decimals up to 2 decimal places.
基本上,我要求输入价格.
Basically, I am asking for a price input.
我想避免使用正则表达式.有办法吗?
I wanted to avoid doing regex. Is there a way to do it?
<input type="number" required name="price" min="0" value="0" step="any">
step="any" 允许任意位数的小数,使用 step=".01",最多允许两位小数.
Instead of step="any", which allows for any number of decimal places, use step=".01", which allows up to two decimal places.
规范中的更多详细信息:https://www.w3.org/TR/html/sec-forms.html#the-step-attribute
More details in the spec: https://www.w3.org/TR/html/sec-forms.html#the-step-attribute
这篇关于在<input type=“number">中允许2位小数.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
JavaScript innerHTML 不适用于 IE?JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不适用于 IE?)
NETWORK_ERROR:XMLHttpRequest 异常 101NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 异常 101)
如何在 IE 中从 Javascript 访问 XHR responseBody(用于二how do I access XHR responseBody (for binary data) from Javascript in IE?(如何在 IE 中从 Javascript 访问 XHR responseBody(用于二进制数据)
document.write() 覆盖文档?document.write() overwriting the document?(document.write() 覆盖文档?)
AngularJS 错误:跨源请求仅支持协议方案:http、datAngularJS Error: Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https(AngularJS 错误:跨源请求仅支持
如何获得 XMLHttpRequest 的响应?How to get the response of XMLHttpRequest?(如何获得 XMLHttpRequest 的响应?)