JavaScript Reference/Javascript Methods/collapse
Версия от 18:30, 25 мая 2010; (обсуждение)
"collapse()" Example
<!--
Example revised from
The Web Programmer"s Desk Reference
by Lazaro Issi Cohen and Joseph Issi Cohen
ISBN: 1593270119
Publisher: No Starch Press 2004
-->
<html>
<body>
<script language="JavaScript">
function function1() {
var choose, range
for (var i = 0; i < document.forms[0].choose.length; i++) {
if (document.forms[0].choose[i].checked) {
choose = document.forms[0].choose[i].value
break
}
}
var x = window.event.clientX
var y = window.event.clientY
if (window.event.srcElement.parentTextEdit) {
range = window.event.srcElement.parentTextEdit.createTextRange()
range.collapse()
range.moveToPoint(x, y)
range.expand(choose)
range.select()
}
}
</script>
<form>
<input type="radio" value="character" checked name="choose">character
<input type="radio" value="word" name="choose">word
<input type="radio" value="sentence" name="choose">sentence
</form>
<p onClick="function1();" style="cursor:hand">
Make a radio selection and then click here
</p>
</body>
</html>
"collapse()" is applied to
+----------------+--------------------------------------------------------------+
| Applied_To |TextRange |
+----------------+--------------------------------------------------------------+
"collapse()" Syntax, Parameters and Note
Note:
Shrinks a text range down to a single insertion point.
Syntax:
textRangeName.collapse(param1)
Parameters:
param1 Optional;
true insertion point is the start of the text
false insertion point is the end of the text