JS calculates the pixel occupied by characters and the truncated string

Source: Internet
Author: User
JS intercepts strings and hides them.

<SCRIPT>
Function substr (OBJ )...{
/** // * Obtain the pixel occupied by the character */
String. Prototype. boldwidth = stringboldwidth;
Function stringboldwidth ()...{
VaR II = 0;
VaR A = This. Replace (/[

 

Use CSS to intercept a string:
Add the following statement to the CSS style:

Overflow: hidden;

White-space: nowrap;

Text-overflow: ellipsis;

In this way, if the character reaches the specified width, it is automatically truncated, followed by a ellipsis. It is much easier to intercept PHP characters!



<HR>
<Style type = "text/CSS">...
. Title
{...}{
Width: 200px;
White-space: nowrap;
Word-break: Keep-all;
Overflow: hidden;
Text-overflow: ellipsis;
}
</Style>

<SPAN class = title> the title displayed on the client is too long. the unused part is omitted and the ellipsis is added. </span>
<HR>
<Div class = title> the client solves the problem. The title is displayed too long. the unused part is omitted and the ellipsis is added. </div>

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.