Spring form:input for number

≯℡__Kan透↙ 提交于 2019-12-06 23:45:34

问题


I am using Spring's form:input as below :

<form:input type="number" .....>

in my jsp but when I check the html that is rendered on the browser it shows like :

type="number" type="text"

i.e., two type attributes are generated in the html.

On the other hand, if I check using inspect element option in 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?


回答1:


Spring form:input tag doesnt have any attribute named type and the type=number used in your code belongs to html5 input tag

Also have a look at HTML Text Input allow only Numeric input

Spring form tld lists the valid attributes of form:input element here




回答2:


HTML 5 with <!DOCTYPE html> has native solution:

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

See also https://github.com/jonstipe/number-polyfill for transparent support in older browsers.




回答3:


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.

I used:

$(".selector").attr({
    "type" : "number",
});


来源:https://stackoverflow.com/questions/27141458/spring-forminput-for-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!