我正在尝试使用焦点函数在文本字段中设置光标。我做了一些研究,但似乎没有任何提供的解决方案在Google Chrome中起作用。在Internet Explorer和Firefox中,此解决方案可以很好地工作:
js代码:
$('#Search').focus(function() {
var SearchInput = $('#Search');
var strLength= SearchInput.val().length;
SearchInput.focus();
SearchInput[0].setSelectionRange(strLength, strLength);
});
HTML代码:
<input type="text" id="Search" value="Hello World" />
这是我的jsfiddle链接。
有没有办法在Google Chrome中使它也能工作?