使用jQuery将焦点设置在文本框上时的IE-10光标位置 [英] IE-10 Cursor position when set focus on textbox using jquery
问题描述
将焦点放在文本框上时,IE -10(窗口-7 SP-1)出现问题.我的光标位置在文本框中的开头.如何设置文本框值的结尾位置.
I have a problem in IE -10(window -7 SP-1) when set focus on a text box. my cursor position at the beginning in text-box. how can i set position End of text-box value.
演示 我正在尝试使用j-query代码解决此问题-
DEMO I am try j-query code for this problem --
var input = $("#txt1"); // textbox Id
var len = input.val().length;
input[0].focus();
input[0].setSelectionRange(len, len);
解决了JQUERY问题,但为什么从IE-10(窗口-7 SP-1)开始设置光标?
WITH JQUERY problem is resolved but why cursor set beginning in IE-10(window -7 SP-1)?
以及任何其他解决方案.
And any any other solution for this.
推荐答案
这似乎是浏览器的一种实现选择.我无法在HTML规范中的任何地方找到当文字输入获得焦点时光标应放置在何处的信息.如果使用鼠标进行输入焦点,则光标将位于IE10,Firefox和Chrome中的单击位置,但没有单击事件,浏览器似乎会做自己的事情-例如,Chrome似乎选择了整个输入的内容.
This appears to be an implementation choice on the part of the browser. I can't find anywhere in the HTML spec where it says where the cursor should be positioned when a text input gains focus. If you use the mouse to give an input focus, the cursor is at the clicked position in IE10, Firefox and Chrome, but absent a click event, the browsers seem to do their own thing - Chrome, for example, appears to select the entire contents of the input.
这篇关于使用jQuery将焦点设置在文本框上时的IE-10光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!