How to make jquery.inputmask work with input type=number?

主宰稳场 提交于 2019-12-05 09:37:57
scunliffe

The jQuery Inputmask plugin (http://plugins.jquery.com/jquery.inputmask/) uses setSelectionRange, selectionStart, selectionEnd (in https://github.com/RobinHerbots/jquery.inputmask/blob/3.x/js/jquery.inputmask-multi.js). These properties/methods have been dropped on <input type="number"/> fields in Chrome when they updated to conform to a W3C change.

If you feel the W3C change to remove these features on number fields was in error, please vote for the Bugzilla bug #24796

There are some hacks to workaround this issue or you may need to resort to using <input type="text">

I have found that using <input type="tel" /> allows for numeric inputs on cell phones, and also allows all the same events to fire as type="text"!

Browsers without support for these types will fall back to using the "text" type.

http://www.caniuse.com/#search=tel

Hopefully this helps someone else.

My solution is add pattern="[0-9]*" to input type="text", or if it didn't work, use input type="tel" - that allows for numeric inputs on phones

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