Home > Web Front-end > JS Tutorial > Cursor's post summary (use of Range)_javascript skills

Cursor's post summary (use of Range)_javascript skills

WBOY
Release: 2016-05-16 19:27:53
Original
1252 people have browsed it

Let’s talk about the common methods of TextRange first

collapse([bStart])
Move the insertion point of Range
bStart true (move to the beginning) false (move to the end)

findText (sText [, iSearchScope] [, iFlags])
Find sText in Range
iSearchScope starting position, search in negative direction
iFlags 2 (whole word match) 4 (case sensitive)

moveStart(sUnit [, iCount])
moveEnd(sUnit [, iCount])
Move the beginning or end of Range
sUnit character(word) word(word) sentence(sentence) textedit(Range)
iCount number of moves, default is 1

moveToPoint(iX, iY)
Move the cursor to coordinates (iX, iY)

pasteHTML(sHTMLText)
Replace in Range html

scrollIntoView([bAlignToTop])
Scroll to display in the current window
bAlignToTop true (Range is at the beginning of the window) false (Range is at the bottom of the window)

select()
Select Range

and then talk about some examples. You can also help to summarize it. It’s hard to find posts, haha ​​
Set the cursor (qiushuiwuhen)


[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]
Set text selection (qiushuiwuhen)


[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
]
Get the current coordinates Series 1

[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute ]
Get the current coordinates Series 2
On October 6, Beijing time, AFP, one of the world's three major news agencies, published a graphic report that Chinese international Sun Jihai has attracted competition from Italian clubs AC Milan and Torino due to his performance in the recent World Cup qualifiers. purchase. The Chinese team only needs to draw with Oman on October 7 to enter the World Cup finals for the first time. The picture shows a file photo of Sun Jihai (right) at the Asian Cup on December 19, 1998.
<script> function setCursor(){ var num=parseInt(document.all.s.value) range=document.all.demo.createTextRange(); if(document.all.collapse.checked){ range.collapse(false); range.moveEnd('character',-1*num); }else{ range.collapse(true); range.moveStart('character',-1+num); } range.select(); } </script>[Ctrl A select all Note: <script> function setSelect(){var range = document.body.createTextRange(); range.moveToElementText(demo) range.moveEnd('character',-1*parseInt(document.all.s.value)); range.moveStart('character',-1+parseInt(document.all.b.value)); range.select(); } </script>If you need to introduce external Js, you need to refresh to execute <script> function GetCursorPos(oTextArea) { s="~!@#$%^"; clipboardData.setData('text',s); show.focus(); document.execCommand('paste'); var arr=show.value.split(s); show.value=arr[1]; show.document.selection.empty(); show.document.selection.createRange().select(); show.focus(); clipboardData.setData('text',arr[0]); document.execCommand('paste'); return arr[0].length; } </script>]
取得当前坐标系列3(Yang)

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template