[Timlinux] The TD content of the JavaScript table is more than three dots wide

Source: Internet
Author: User

1. Ideas
    • CSS control TD content automatically shrinks to three points
    • JS Control mouse Hover display all the contents of TD
2. Implement

HTML code:

<!DOCTYPE HTML><HTML><Head>    <MetaCharSet= "Utf-8">    <title>TABLE/TD Automatically Hide content</title>    <Linkrel= "stylesheet"href= "My.css" /></Head><Body>    <TableID= "Idmytable" > <tr> <td> This is a normal display of content </td> <td> This is a content that automatically hides extra-long text content, and the rest will automatically be based on Coltsfoot Hidden, function can execute normally. </td> </tr> </table> <script type= "application/javascript "src= "My.js"></Script></Body></HTML>

CSS code:

Table{width:400px;Border-collapse:collapse;/*set the merge border model for a table*/Table-layout:fixed;/*set the table layout algorithm, only the TD property after setting this value is valid*/}TD{Border:1px solid Blue;Word-break:Keep-all;/*line breaks at the appropriate hyphenation point*/White-space:nowrap;/*text in a specified paragraph does not wrap*/Overflow:Hidden;/*What happens when the content overflows the element box*/Text-overflow:ellipsis;/*What happens when text overflows containing elements, ellipsis meaning ellipsis*/}

JS Code:

Window.onload =function () {    varAlltds = document.getElementsByTagName (' TD ');  for(vari = 0; i < alltds.length; i++) {        varTD =Alltds[i]; Td.onmouseover=function(EV) {if( This. clientwidth < This. ScrollWidth) {                 This. SetAttribute (' title ', This. textcontent);        }        }; Td.onmouseleave=function(EV) { This. RemoveAttribute (' title ');    }; }};
3. Effects

[Timlinux] The TD content of the JavaScript table is more than three dots wide

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.