您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“web開發(fā)中如何將鼠標(biāo)焦點(diǎn)定位到文本框最后”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“web開發(fā)中如何將鼠標(biāo)焦點(diǎn)定位到文本框最后”這篇文章吧。
經(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
以上是“web開發(fā)中如何將鼠標(biāo)焦點(diǎn)定位到文本框最后”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。