input輸入框光標位置問題


問題


模糊搜索自動選中后,光標定位在輸入處,應定位在末尾處。

解決

setTimeout(() => {
    let obj = this.$refs.custominput;
    let value = obj.value;
    if (document.selection) {
      var sel = obj.createTextRange();
      sel.moveStart('character', value.length);
      sel.collapse();
      sel.select();
    } else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
        obj.selectionStart = obj.selectionEnd = value.length;
    }
}, 0);

解決后效果圖如下:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM