填写表单域时,只应将数字作为输入并显示在表单域上。当填写其他字符如'a'时,它们不显示在表单域上。只能看到以前给出的数字。应该使用core来完成javascript。
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_input_number
<input type="number">
That should be what you need.
Edit : After seeing your comment: This is not your solution, because you want a javascript solution. This should have been in your question, because it is essential to answering the question.
Take a look at this
How To Only Allow Alpha Numeric Chars With JavaScript
and try to replace the regexp with if(!/^[0-9]+$/.test(name))
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.