猿问

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.

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


眼眸繁星
浏览 4404回答 0
0回答

茅侃侃

楼主,你好!这个问题可以在&nbsp;MDN&nbsp;上查到说明。传送门,&nbsp;stackoverflow&nbsp;给的答案请注意, 根据 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.
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答