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

      

  • 相关阅读:
    redis操作
    MySQL架构
    MySQL查询缓存
    MySQL数据备份与还原
    Sql性能优化
    Notepad++中每一行的开头和结尾添加引号?
    分组聚合
    Python3用scan和delete命令批量清理redis数据
    VUE+django
    python转化13位时间戳
  • 原文地址:https://www.cnblogs.com/webSong/p/9861102.html
Copyright © 2011-2022 走看看