当前位置: 首页 > news >正文

郑州宣传片制作/朝阳seo推广

郑州宣传片制作,朝阳seo推广,网站诊断与优化的作用,广安建设厅官方网站光标位置后插入 其实光标位置后插入,我的做法是很简单的,就一句话。vue版本如下: [AppleScript] 纯文本查看 复制代码 ? 1 2 3 4 let focusinput this.inputEl.selectionStart if (this.nowSelect) { item.subsText ${item.subsTe…

光标位置后插入

其实光标位置后插入,我的做法是很简单的,就一句话。vue版本如下:

[AppleScript] 纯文本查看 复制代码

?

1

2

3

4

let focusinput = this.inputEl.selectionStart

 if (this.nowSelect) {

   item.subsText = `${item.subsText.substr(0, focusinput)}${this.nowLabel}${item.subsText.substring(focusinput, item.subsText.length)}`

 }

其中this.inputEl就是input元素

item.subsText就是input中文本

this.nowLabel就是要插入的内容

插入就一句话判断0到selectionStart的位置,然后把文本查到后面就可以了。

封装方法

网上也有一些封装的方法,看了一下,大致可以用。如下:

获取光标位置函数

[AppleScript] 纯文本查看 复制代码

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

// 获取光标位置

function getCursortPosition (textDom) {

 var cursorPos = 0;

 if (document.selection) {

  // IE Support

  textDom.focus ();

  var selectRange = document.selection.createRange();

  selectRange.moveStart ('character', -textDom.value.length);

  cursorPos = selectRange.text.length;

 }else if (textDom.selectionStart || textDom.selectionStart == '0') {

  // Firefox support

  cursorPos = textDom.selectionStart;

 }

 return cursorPos;

}


设置光标位置函数:

[AppleScript] 纯文本查看 复制代码

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

// 设置光标位置

function setCaretPosition(textDom, pos){

 if(textDom.setSelectionRange) {

  // IE Support

  textDom.focus();

  textDom.setSelectionRange(pos, pos);

 }else if (textDom.createTextRange) {

  // Firefox support

  var range = textDom.createTextRange();

  range.collapse(true);

  range.moveEnd('character', pos);

  range.moveStart('character', pos);

  range.select();

 }

}


获取光标选中文字函数:

[AppleScript] 纯文本查看 复制代码

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

// 获取选中文字

function getSelectText() {

 var userSelection, text;

 if (window.getSelection) {

  // Firefox support

  userSelection = window.getSelection();

 } else if (document.selection) {

  // IE Support

  userSelection = document.selection.createRange();

 }

 if (!(text = userSelection.text)) {

  text = userSelection;

 }

 return text;

}


选中特定范围的文本函数:

[AppleScript] 纯文本查看 复制代码

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

/**

* 选中特定范围的文本

* 参数:

*  textDom [JavaScript DOM String] 当前对象

*  startPos [Int] 起始位置

*  endPos [Int] 终点位置

*/

function setSelectText(textDom, startPos, endPos) {

 var startPos = parseInt(startPos),

  endPos = parseInt(endPos),

  textLength = textDom.value.length;

 if(textLength){

  if(!startPos){

   startPos = 0;

  }

  if(!endPos){

   endPos = textLength;

  }

  if(startPos > textLength){

   startPos = textLength;

  }

  if(endPos > textLength){

   endPos = textLength;

  }

  if(startPos < 0){

   startPos = textLength + startPos;

  }

  if(endPos < 0){

   endPos = textLength + endPos;

  }

  if(textDom.createTextRange){

   // IE Support

   var range = textDom.createTextRange();

   range.moveStart("character",-textLength);

   range.moveEnd("character",-textLength);

   range.moveStart("character", startPos);

   range.moveEnd("character",endPos);

   range.select();

  }else{

   // Firefox support

   textDom.setSelectionRange(startPos, endPos);

   textDom.focus();

  }

 }

}


在光标后插入文本函数:

[AppleScript] 纯文本查看 复制代码

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

/**

* 在光标后插入文本

* 参数:

*  textDom [JavaScript DOM String] 当前对象

*  value [String] 要插入的文本

*/

function insertAfterText(textDom, value) {

 var selectRange;

 if (document.selection) {

  // IE Support

  textDom.focus();

  selectRange = document.selection.createRange();

  selectRange.text = value;

  textDom.focus();

 }else if (textDom.selectionStart || textDom.selectionStart == '0') {

  // Firefox support

  var startPos = textDom.selectionStart;

  var endPos = textDom.selectionEnd;

  var scrollTop = textDom.scrollTop;

  textDom.value = textDom.value.substring(0, startPos) + value + textDom.value.substring(endPos, textDom.value.length);

  textDom.focus();

  textDom.selectionStart = startPos + value.length;

  textDom.selectionEnd = startPos + value.length;

  textDom.scrollTop = scrollTop;

 }

 else {

  textDom.value += value;

  textDom.focus();

 }

}


复制和剪切板

监听页面复制,添加一些版权信息,代码如下:

[AppleScript] 纯文本查看 复制代码

?

1

2

3

4

5

6

7

8

document.addEventListener('copy', function (event) {[/font][/backcolor][/color][/align]    var clipboardData = event.clipboardData || window.clipboardData;

    if (!clipboardData) { return; }

    var text = window.getSelection().toString();

    if (text) {

        event.preventDefault();

        clipboardData.setData('text/plain', text + '\n\n haorooms博客版权所有');

    }

})

http://www.jmfq.cn/news/4961197.html

相关文章:

  • 网站icp备案管理系统/广点通和腾讯朋友圈广告区别
  • 医院网站站群建设/seo查询
  • c语言做项目网站/免费html网站制作成品
  • 网站开发者/百度图片查找
  • 杭州网站排名优化公司/抖音推广平台
  • 学校网站建设目的与意义/如何用网站模板建站
  • 仿网站ppt怎么做/百度热搜榜
  • 北京网站建设app/seo模拟点击软件
  • 网站备案没公司/长春网站优化
  • 青岛网站建设效果/最近发生的热点新闻
  • 官方网站建设银行2010年存款利息/电商怎么做新手入门
  • 四川省建设执业注册中心网站/谷歌商店paypal三件套
  • wordpress放哪个目录/天天seo百度点击器
  • 网站手机模板和pc模板要分开做/如何快速提升网站关键词排名
  • web端是什么意思/贺州seo
  • 网站建设新趋势/关键词优化价格
  • 网站整体框架/中国最新消息今天
  • 网站做web/上海企业推广
  • 优惠券网站制作教程/百度平台商家我的订单查询
  • wordpress 友链/湘潭seo公司
  • 网站怎么做解析/seo网站排名推广
  • 京美建站/新闻头条今日要闻10条
  • 一个网站需要几个人做/最近新闻摘抄50字
  • 医院网站可信认证必须做吗/厦门seo排名
  • 创意网站建设/郑州网站开发公司
  • 陕西建设厅官网系统平台/东莞网站seo推广
  • 弹簧机 东莞网站建设/关键词优化公司哪家推广
  • 网站建设公司的业务规划/成都高新seo
  • 一屏网站模板下载 迅雷下载 迅雷下载地址/电商网站模板
  • 四线城市做网站建设怎么样/怎么提交网址让百度收录