HTML long text intercepts the same two methods that contain HTML code

Source: Internet
Author: User
As the title says we can use CSS to truncate the string: Ie,firefox,opera, Safari are compatible can also use JS interception, specifically implemented as follows, I hope to help you

Method One: Use CSS to truncate strings: Ie,firefox,opera, Safari compatible

Copy Code code as follows:


. sublongtext{


width:150px;


height:24px;


Overflow:hidden;


White-space:nowrap;


text-overflow:ellipsis;


text-overflow:ellipsis;/* Ie/safari * *


-ms-text-overflow:ellipsis;


-o-text-overflow:ellipsis;/* Opera * *


-moz-binding:url ("ellipsis.xml#ellipsis");/*firefox*/


}


<span class= "Sublongtext" > arbitrary length text </span>


method Two: Use JS intercept

Copy Code code as follows:


<HTML>
<HEAD>
<title>jquery text interception method </TITLE>
<meta http-equiv= Content-type "content=" text/html; Charset=utf-8 ">
<script type=" Text/javascript "src=" jquery-1.3.2.js "></script>
<script Type= "Text/javascript" >
$.fn.substr = function (length,content) {
$ (this). each (function (i,item) {
var val=$ (item). HTML ();
if (!val) return;
if (val.length>length) {
val = val.substring (0,length);
val + = Content | | "..."
$ (item). HTML (val);
}
});
}
Function Subtdcontent () {
$ (' TD '). SUBSTR (20);
}
</script>
</HEAD>
<body onload= "javascript:subtdcontent ();" >
<table style= "border:1px solid #b3c0f5;" border= "1" >
<tr>
<td> I am code: $.FN.SUBSTR = Fun Ction (l,c) {$ (this). each (function (i,item) </td>
<td> The following two ways can resolve textarea height of automatic adaptive class capacity </td>
<td> the following two ways to resolve textarea lines </td>
</tr>
</table>
</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.