input光標位置

兼容谷歌火狐-input光標位置spa

input框在沒有添加任何效果的狀況下,輸入文字後光標始終在最後的位置,谷歌||火狐效果同樣事件

可是在給input加入點擊事件後   谷歌:input框插入文字後,光標會自動到最後位置input

                火狐:input框插入文字後,光標在插入文字的後面it

兼容:光標在文字的最後面io

  function moveEnd(obj){
  obj.focus();
  var len = obj.value.length;
  if (document.selection) {
  var sel = obj.createTextRange();
  sel.moveStart('character',len);
  sel.collapse();
  sel.select();
  } else if (typeof obj.selectionStart == 'number' && typeof obj.selectionEnd == 'number') {
  obj.selectionStart = obj.selectionEnd = len;
    }
  }

 兼容:光標在中間插入文字的後面      function

   function moveEnd(obj){
    obj.focus();
    var len = obj.value.length;
    if (document.selection) {
    var sel = obj.createTextRange();
    sel.moveStart('character',len);
    sel.collapse();
    sel.select();
    } else if (typeof obj.selectionStart == 'number' && typeof obj.selectionEnd == 'number') {
    
  setCursorPosition(obj,obj.selectionStart)select

      }

    }im

  設置光標位置:db

  setSelectionRange(obj.selectionStart,obj.selectionStart);img

  selectionStart       輸入性元素selection起點的位置,可讀寫。   selectionEnd       輸入性元素selection結束點的位置,可讀寫。   setSelectionRange(start, end)       設置輸入性元素selectionStart和selectionEnd值
相關文章
相關標籤/搜索