zoukankan      html  css  js  c++  java
  • input光标位置

    兼容谷歌火狐-input光标位置

    input框在没有添加任何效果的情况下,输入文字后光标始终在最后的位置,谷歌||火狐效果一样

    但是在给input加入点击事件后   谷歌:input框插入文字后,光标会自动到最后位置

                    火狐:input框插入文字后,光标在插入文字的后面

    兼容:光标在文字的最后面

      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 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)

          }

        }

      设置光标位置:

      setSelectionRange(obj.selectionStart,obj.selectionStart);

      selectionStart
          输入性元素selection起点的位置,可读写。
      selectionEnd
          输入性元素selection结束点的位置,可读写。
      setSelectionRange(start, end)
          设置输入性元素selectionStart和selectionEnd值
  • 相关阅读:
    elastic-job详解(二):作业的调度
    elastic-job详解(一):数据分片
    定时任务的分布式调度
    HBase多条件及分页查询的一些方法
    TP6多应用模式配置
    Swoole WebSocket 服务端如何主动推送消息?
    mysql(多级分销)无限极数据库设计方法
    django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).
    Centos7安装并配置Python3环境
    short url短链接原理
  • 原文地址:https://www.cnblogs.com/Kyaya/p/6023369.html
Copyright © 2011-2022 走看看