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 = function (l,c) {$ (this). each (function (I,item) </td>
<td> The following two ways can be resolved textarea row height automatic adaptation class capacity </td>
<td> the following two ways to resolve textarea line </td>
</tr>
</table>
</BODY> </HTML>