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>