zoukankan      html  css  js  c++  java
  • js获取光标位置并插入内容

    先来几个网上找的参考资源,我爱互联网,互联网使我变得更加强大。

    https://blog.csdn.net/mafan121/article/details/78519348 详细篇,该作者很用心的解释了每一个api的用法。

    https://blog.csdn.net/smartsmile2012/article/details/53642082 https://blog.csdn.net/liushuijinger/article/details/48834541 在光标位置插入内容

    https://blog.csdn.net/wangzhikui1/article/details/52236091 设置光标的出现的位置

    https://segmentfault.com/q/1010000006149636 一个思路清奇的朋友写的基于vue的光标插入内容

    接下来就是我自己基于以上材料思路自己写的基于vue2.0的了。

    getCursorPosition (event) {
                const editEl = event.target;
                // return console.log(editEl);
                if (editEl.selectionStart ||editEl.selectionStart === 0) {
                    // 非IE浏览器
                    this.cursorPosition = editEl.selectionStart;
                } else {
                    // IE
                    const range = document.selection.createRange();
                    range.moveStart('character', -editEl.value.length);
                    this.cursorPosition = range.text.length;
                }
                console.log(this.cursorPosition);
            }
    

      

  • 相关阅读:
    MySQL主主同步方案
    Mysql增量备份与恢复
    配置合适的存储引擎
    基于Amoeba读写分离
    部署myaql主从异步复制
    MySQL完全备份操作
    echo 命令详解
    ELK 基本部署
    zabbix 简介
    基于 Git Tag 发布及回滚代码
  • 原文地址:https://www.cnblogs.com/webSong/p/9861102.html
Copyright © 2011-2022 走看看