linux 通配符使用小结
2015-10-14 15:47
666 查看
项目开发中需要计算textarea光标的开始位置与结束位置,以便于在指定位置插入文本。下面这段代码测试通过,能够得到光标的开始位置与结束位置。var er = document.selection.createRange(),start = 0,end = 0;
if(er.parentElement().id === this.id){ // create a selection of the whole textarea var er1 = document.body.createTextRange(); er1.moveToElementText(this); //两个range,一个是已经选择的text(er),一个是整个textarea(er1) //er1.compareEndPoints()比较两个端点,如果er1比er更往左(further to the left),则 //返回小于0的值,则er1往右移一点,直到两个er的start相同。 // calculate selection start point by moving beginning of er1 to beginning of er for (start = 0;er1.compareEndPoints('StartToStart',er) < 0;start++){ er1.moveStart('character', 1); } // get number of line breaks from textarea start to selection start and add them to start // 计算一下\n for (var i = 0; i <= start;i++){ if (this.value.charAt(i) == '\n'){ start++; } } // create a selection of the whole textarea var er1 = document.body.createTextRange(); er1.moveToElementText(this); // calculate selection end point by moving beginning of er1 to end of er for (end = 0;er1.compareEndPoints('StartToEnd',er) < 0;end++){ er1.moveStart('character',1); } // get number of line breaks from textarea start to selection end and add them to end for (var i = 0;i <= end;i++){ if (this.value.charAt(i) == '\n'){ end ++; } } }
相关文章推荐
- JDK 1.7安装详解(CentOS 6.4)
- linux 压缩和归档
- [内存管理] linux kernel内存映射实例分析
- linux并发服务器(1)(想法补充)
- PF_RING安装
- linux awk命令详解
- centos与RHEL的关系
- 如何查看 linux 内核源代码
- CentOS 安装jdk1.7 32位
- LINUX下通过C++访问SQLSERVER数据库
- Linux rpm 命令参数使用详解
- Linux CentOS VPS 性能评测 跑分
- Linux内核加载过程
- linux iptables原理及配置详解
- linux 启动过程关键点
- linux文件的输入输出
- linux下搭建pentaho服务器
- gdb结合coredump定位崩溃进程
- 如何解决windows系统和linux系统中端口被占用的问题
- CentOS最小化安装后,增加GNOME桌面