Html 弹簧形式:输入数字
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27141458/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring form:input for number
提问by iAmLearning
I am using Spring's form:input as below :
我正在使用 Spring 的 form:input 如下:
<form:input type="number" .....>
in my jsp but when I check the html that is rendered on the browser it shows like :
在我的 jsp 中,但是当我检查浏览器上呈现的 html 时,它显示如下:
type="number" type="text"
i.e., two type
attributes are generated in the html.
即type
在html中生成了两个属性。
On the other hand, if I check using inspect element optionin the browser, it shows correct - only type="number"
as expected.
Edit- My Question: Why am I getting two type attributes in generated html (type="number" type="text"
) ? How to get it resolved?
另一方面,如果我在浏览器中使用检查元素选项进行检查,它会显示正确 - 仅type="number"
按预期进行。
编辑- 我的问题:为什么我在生成的 html ( type="number" type="text"
) 中得到两个类型属性?如何解决?
采纳答案by Santhosh
Spring form:input
tag doesnt have any attribute named type
and the type=number
used in your code belongs to html5input tag
Springform:input
标签没有任何命名type
的属性,并且type=number
在您的代码中使用的属于html5输入标签
Also have a look at HTML Text Input allow only Numeric input
Spring form tld lists the valid attributes of form:input
element here
Spring 表单 tld 在这里列出了form:input
元素的有效属性
回答by tk_
HTML 5with <!DOCTYPE html>
has native solution:
HTML 5与<!DOCTYPE html>
拥有本土的解决方案:
<input type="number">
<input type="number">
Beware that it does not behave in standard way in some browsers.
请注意,它在某些浏览器中的行为不符合标准。
Try input type="number"to see the HTML5 version in action.
尝试输入 type="number"以查看正在运行的 HTML5 版本。
See also https://github.com/jonstipe/number-polyfillfor transparent support in older browsers.
另请参阅https://github.com/jonstipe/number-polyfill以了解旧浏览器中的透明支持。
回答by Ben Vae
I know this is old, but i found a solution that works just fine for me.
我知道这很旧,但我找到了一个对我来说很好用的解决方案。
The spring:input
form tag doesnt support the type
attribute and there is no such thing as spring:number
.
But you can use jquery to add the type="number"
attribute to the parsed html.
该spring:input
表单标签犯规支持type
的属性并没有这样的事情spring:number
。但是您可以使用 jquery 将type="number"
属性添加到解析的 html 中。
I used:
我用了:
$(".selector").attr({
"type" : "number",
});