How to select a scroll text box from a row to a row

Source: Internet
Author: User

// ======================================
// Function: accurately locates the scroll text box
// Input parameters:
// Self scroll text box object
// _ Startline start line
// _ Endline end row
// _ Start position of the Start row of startpoint
// _ Endpoint end position of the number of end rows
// Call method:
// ① The same row, from the starting position to the ending position:
// Seltolinepoint (self, 2, 2, 0/1, 0)
// ② Different rows, from a starting position to the ending position:
// Seltolinepoint (self, 2, 4, 3, 0)
// ③ Different rows, from a starting position to a ending position:
// Seltolinepoint (self, 2, 4, 3, 9)
// ======================================
Function seltolinepoint (self, _ Startline, _ endline, _ startpoint, _ endpoint, _ Len ){
VaR src = self;
VaR OTR = self. createTextRange ();
VaR text = self. innertext;
VaR textlength = text. length;
 
Conts = [0];
Startx = SRC. createTextRange (). getclientrects () [0]. Left;
Starty = SRC. createTextRange (). getclientrects () [0]. Top;
Stepy = 3; // the step that the cursor moves down. It cannot be greater than the word height in textarea.
Currentscr = 0; // current scroll bar position
Stepscr = 30; // the step of scroll down, which cannot be greater than the height of textarea
 
While (1 ){
SRC. scrolltop = currentscr
Currenty = starty
While (1) {// The cursor moves down from the beginning of the textarea content, traversing each row, and recording the positions of each row in the conts []
OTR. movetopoint (startx, currenty)
OTR. moveend ("character", textlength)
VaR _ otr_line_length = OTR. Text. length;
Cont = textlength-_ otr_line_length;
If (cont> = textlength ){
Break
}
If (cont> conts [conts. Length-1]) {
Conts [conts. Length] = cont
}
Currenty + = stepy
}
If (currentscr> = SRC. scrollheight ){
Break
}
Currentscr + = stepscr;
}
 
If (_ endline = "")
_ Endline = _ Startline;
_ Startline = parseint (_ Startline );
_ Endline = parseint (_ endline );
 
If (isfinite (_ Startline) & isfinite (_ endline) & _ Startline> 0 & _ endline> 0 ){
// Check the parameter Validity
If (_ Startline> conts. Length | _ endline> conts. Length ){
Alert ("only" + conts. Length + "rows in total, check and try again. ");
Return;
}

// If the end row is forcibly adjusted before the start row
If (_ endline <_ Startline ){
_ Endline = _ Startline;
End. value = _ endline;
}

SRC. scrolltop = 0;
OTR. movetopoint (startx, starty); // The cursor returns to the beginning of the textarea content
St = conts [_ Startline-1];

If (ST> _ startpoint ){
St = ST + _ startpoint;
} Else {
VaR _ righttextlen = 0;
For (VAR m = 0; m <conts. length; m ++ ){
If (conts [m] <_ startpoint ){
_ Righttextlen = _ startpoint-conts [m];
St = _ startpoint-_ righttextlen;
If (_ endline = _ Startline ){
_ Endline ++;
}
} Else {
Break;
}
}

If (ST + _ righttextlen <textlength ){
St = ST + _ righttextlen;
}

}

Texprestart = text. substr (0, St );
Texprestart = text. substr (0, ST ). replace (/R/g, ""); // The string from the beginning of the textarea content to the start point. Since the movestart method treats rn as a character, you need to modify the count.

St = texprestart. length;
OTR. movestart ("character", St );
En = textlength;
If (_ endline <conts. Length ){
En = conts [_ endline];
If (_ endpoint> 0 ){
VaR lalinelen = conts [_ endline]-conts [_ endline-1];
En = en-lalinelen + _ endpoint;
}
}
Texpreend = text. substr (0, en ). replace (/R/g, "") // The string from the beginning of the textarea content to the end point. Because the moveend method treats rn as a character, the Count needs to be corrected.
En = texpreend. Length
VaR _ endx = en-ST;
OTR. moveend ("character", _ endx );
OTR. Select ();
}
 
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.