简体   繁体   English

无法将setSelectionRange添加到所选元素

[英]cant add setSelectionRange to selected element

I've selected input using "getElementById". 我已经使用“ getElementById”选择了输入。 After I want add "setSelectionRange" method to that element. 在我想要将“ setSelectionRange”方法添加到该元素之后。 But there is an error "property 'setselectionrange' does not exist on type 'htmlelement' " . 但是出现错误“类型'htmlelement'上不存在属性'setselectionrange'”。 What could be the problem? 可能是什么问题呢?

const textfield = document.getElementById("masktextfield")
console.log(textfield)

that's what shows in console 这就是控制台中显示的内容

在此处输入图片说明

now adding "setselectionrange" 现在添加“ setselectionrange”

textfield.setSelectionRange(0,0) // property 'setselectionrange' does not exist on type 'htmlelement'

 const textfield = document.getElementById("masktextfield"); textfield.focus(); textfield.setSelectionRange(2, 5); 
 <input type="text" id="masktextfield" value="sathish"/> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM