JavaScript Reference/Javascript Methods/collapse

Материал из Web эксперт
Перейти к: навигация, поиск

"collapse()" Example

   <source lang="javascript">
  

<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>

Make a radio selection and then click here

</body> </html>


     </source>
   
  


"collapse()" is applied to

   <source lang="javascript">

+----------------+--------------------------------------------------------------+ | Applied_To |TextRange | +----------------+--------------------------------------------------------------+

     </source>
   
  


"collapse()" Syntax, Parameters and Note

   <source lang="javascript">

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 
   
     
     </source>