admin管理员组文章数量:1314832
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.
Guess I can't use setSelectionRange
on emails. So, any other solutions on how to set my cursor position in the input text box (without changing the type email)?
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.
Guess I can't use setSelectionRange
on emails. So, any other solutions on how to set my cursor position in the input text box (without changing the type email)?
-
1
There is no way around it if you want to keep the
type="email"
. Thetype="number"
has the same issue... you could voice your opinion in the discussion on w3 (it is specifically for number inputs; I haven't searched for a email type input discussion). Similar to stackoverflow./questions/21177489/… – Mottie Commented Oct 30, 2014 at 16:56
1 Answer
Reset to default 5It is true, it seems that there is a bug when using the setSelectionRange
function for email input. So what can be done is to modify the type of the input so that setSelectionRange
works and not an error.
$('#ID').focus(function () {
var input = this;
setTimeout(function () {
$(input).attr('type', 'text');
input.setSelectionRange(0, 0);
$(input).attr('type', 'email');
}, 100);
});
本文标签: javascriptType Email doesn39t support selectionrangeStack Overflow
版权声明:本文标题:javascript - Type Email doesn't support selectionrange - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741971391a2407859.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论