jquery gets automatic truncation of long text content, displayed as ellipses

Source: Internet
Author: User

If the TD content is too large in table, it will be the TD support is very wide, it looks ugly.

If you can make the TD both Beautiful. You can see the full effect.

We then need to give the specified style before generating the TD:

This is achieved using jquery.

//after the page loads, set the. style. JQuery (function(){       //Use the ID selector, for example: Tab Object->tr->td object. $ ("#high_light tr TD"). each (function(i) {//gets the text of the current object of the TD, if the length is greater than 25;          if($( This). Text (). length>25){                  //set the Title property to TD and set the full value of TD. to the title property. $( This). attr ("title", $ ( This). text ()); //gets the value of the TD and intercepts it.  Assigns a value to the text variable to save.     vartext=$ ( This). Text (). substring (0,25) + "..."; //re-assign the TD value; $( This). text (text);  }        });  }); 

<HTML>        <Head>           <title>Test<title>       </Head>               <TableID= "High_light">                    <TR>                           <TD>This is a long text content, test whether the normal interception. This is a long text content, testing whether the normal interception. This is a long text content, testing whether the normal interception. This is a long text content, testing whether to intercept normally. </TD>                    </TR>        </Table>  </HTML>  


from:http://zhouhaitao.iteye.com/blog/1160694

jquery gets automatic truncation of long text content, displayed as ellipses

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.