I'm trying to set my cursor to the position of the beginning when I'm on focus of a text box.(当我将焦点放在文本框上时,我试图将光标设置在开始位置。)
This is what I have:(这就是我所拥有的:)
$("ID").focus(function () {
var input = this;
setTimeout(function() {
input.setSelectionRange(0, 0);
}, 0);
});
But I get this error every time I try to load the script:(但是,每次尝试加载脚本时都会出现此错误:)
Uncaught InvalidStateError: Failed to execute 'setSelectionRange' on 'HTMLInputElement': The input element's type ('email') does not support selection.(未捕获的InvalidStateError:无法在“ HTMLInputElement”上执行“ setSelectionRange”:输入元素的类型(“电子邮件”)不支持选择。)
Guess I can't use setSelectionRange
on emails.(猜猜我不能在电子邮件上使用setSelectionRange
。)
So, any other solutions on how to set my cursor position in the input text box (without changing the type email)?(那么,关于如何在输入文本框中设置光标位置的其他解决方案(不更改电子邮件类型)呢?)
ask by Norman In translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…