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值
相关文章
相关标签/搜索