如下所示:
$.fn.setCursorPosition = function(position) { if (this.lengh == 0) return this; return $(this).setSelection(position, position);};$.fn.setSelection = function(selectionStart, selectionEnd) { if (this.lengh == 0) return this; input = this[0]; if (input.createTextRange) { var range = input.createTextRange(); range.collapse(true); range.moveEnd('character', selectionEnd); range.moveStart('character', selectionStart); range.select(); } else if (input.setSelectionRange) { input.focus(); input.setSelectionRange(selectionStart, selectionEnd); } return this;};$.fn.focusEnd = function() { this.setCursorPosition(this.val().length);};以上這篇jQuery設(shè)置聚焦并使光標位置在文字最后的實現(xiàn)方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持武林網(wǎng)。
新聞熱點
疑難解答