Test the word selection code

Source: Internet
Author: User
< Script >

Document. Body. onload=TT;
FunctionTT ()
{
Alert ('ddddddddd ');
}
VaRB;

FunctionTe ()//Onselect event
{
B=1;
}

Function A () // Onmouseup event
{
If (B = 1 ){
Alert (document. selection. createRange (). Text );
B = 0 ;
}
}
</ Script >
< Body Onselect = "Javascript: Te ();" Onmouseup = "Javascript: ();" >
Onselectstart = "alert ('start ');"
Onmouseup = "alert (document. selection. createRange (). Text );"
// Firefox uses window. getselec ()
Only when the web page is tested and tested is killed
< BR >
Dddddddddddddd
< Script Language = "JavaScript" >
Function Seltext (){
Document. selection. createRange ();
Document. All. testtext. Value = Unescape (document. selection. createRange (). Text );
Alert ( " Width on the left side of the selection area: " + Document. selection. createRange (). boundingleft );
Alert ( " Height above the constituency: "   + Document. selection. createRange (). boundingtop );
Alert ( " Selected area height: "   + Document. selection. createRange (). boundingheight );
Alert ( " Selection width: "   + Document. selection. createRange (). boundingwidth );
}
</ Script >
< Input Type = "Text" ID = "Testtext" Name = "Testtext" Value = "" Accesskey = "" >
< Input Type = "Button" Name = "Btntest" Value = "Test" Onclick = "Seltext ()" >
< HR >

Object: Document. selection. createRange (); The textrange object is returned.<BR>

Textrange attributes<BR>

Boundingheight gets the height of the rectangle bound to the textrange object. < BR >
Boundingleft gets the distance between the left side of the rectangle bound to the textrange object and the left side of the rectangle containing the textrange object. < BR >
Boundingtop gets the distance between the top edge of the bound textrange object and the top edge that contains the textrange object. < BR >
Boundingwidth retrieves the width of the rectangle that bounds the textrange object. < BR >
Htmltext gets the width of the rectangle bound to the textrange object. < BR >
Offsetleft obtains the left position of the object relative to the layout or the parent coordinate specified by the offsetparent attribute. < BR >  
Offsettop obtains the top position of an object relative to the layout or the parent coordinate specified by the offsettop attribute. < BR >
Set or retrieve text in the range of text. < BR >
</ Body >

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.