滚动到 html 输入的插入符号位置
function sel() {
document.getElementById('testid').focus();
document.getElementById('testid').setSelectionRange(10, 10);
}
<input style="width:50px" id="testid" value="abcdefghijklmnopqrst">
<button onclick="sel()">select 10,10</button>
input.setSelectionRange(10,10) 第一次不将值滚动到插入符号位置。 滚动到插入符号是否可行?
function sel() {
document.getElementById('testid').focus();
document.getElementById('testid').setSelectionRange(10, 10);
}
<input style="width:50px" id="testid" value="abcdefghijklmnopqrst">
<button onclick="sel()">select 10,10</button>
input.setSelectionRange(10,10) not scrolling the value to the caret position for the first time.
Is it feasible to scroll to the caret?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

交换它们
以上在我的 Chrome 中有效。如果这对你不起作用,你可能需要暂停
Swap them
The above works in my Chrome. You many need a timeout if it does not work for you