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)
]
Set text selection (qiushuiwuhen)
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
]
<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)
Statement: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