Type Email doesn't support selectionrange
当我将焦点放在文本框上时,我正在尝试将光标设置到开头的位置。这就是我所拥有的:
1 2 3 4 5 6 | $("ID").focus(function () { var input = this; setTimeout(function() { input.setSelectionRange(0, 0); }, 0); }); |
但是每次尝试加载脚本时都会出现此错误:
Uncaught InvalidStateError: Failed to execute 'setSelectionRange' on 'HTMLInputElement': The input element's type ('email') does not support selection.
猜猜我不能在电子邮件上使用
是的,使用
1 2 3 4 5 6 7 8 | $('#ID').focus(function () { var input = this; setTimeout(function () { $(input).attr('type', 'text'); input.setSelectionRange(0, 0); $(input).attr('type', 'email'); }, 100); }); |