input type=number 获取焦点报错

在vue页面使用标签

 <input type="number" min="0" max="5000" v-model="choosePayDef" placeholder="价值多少钱?">

在页面中点击这个输入框,就会报错为

Uncaught DOMException: Failed to execute 'setSelectionRange' on 'HTMLInputElement': The input element's type ('number') does not support selection.

请问这个问题如何解决呢?

阅读 3.8k
1 个回答

楼主,你好!这个问题可以在 MDN 上查到说明。传送门, stackoverflow 给的答案

请注意, 根据 WHATWG forms spec表单规范 , 从chrome 33版本开始, chrome浏览器只支持获取type为text, search, URL, tel and password的input元素的selectionStart, selectionEnd 和 setSelectionRange 属性, 在其余类型中尝试获取这些属性chrome会提示错误。 举例说明,当尝试对<input type="number"> 做上述操作时, chrome浏览器会提示以下错误信息: "Failed to read the 'selectionStart' property from 'HTMLInputElement': The input element's type ('number') does not support selection." 相关链接: question on StackOverflow, whatwg bug, Chromium bug.

如有帮助,麻烦点击下采纳,谢谢~

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题