abstrait:本文主要分享了將鼠標(biāo)焦點(diǎn)定位到文本框最后的實(shí)例代碼。具有很好的參考價(jià)值,下面跟著小編一起來看下吧經(jīng)測試,兼容IE8//設(shè)置焦點(diǎn)相關(guān)---begin //用法:$("#txtInput").val("你好").focusEnd(); $.fn.setCursorPosition = function (position) 
本文主要分享了將鼠標(biāo)焦點(diǎn)定位到文本框最后的實(shí)例代碼。具有很好的參考價(jià)值,下面跟著小編一起來看下吧
經(jīng)測試,兼容IE8
//設(shè)置焦點(diǎn)相關(guān)---begin //用法:$("#txtInput").val("你好").focusEnd(); $.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 () { if (this.val() != undefined) { this.setCursorPosition(this.val().length); } } //設(shè)置焦點(diǎn)相關(guān)---end
更多關(guān)于將鼠標(biāo)焦點(diǎn)定位到文本框最后的方法請關(guān)注PHP中文網(wǎng)(ipnx.cn)其他文章!