The page gets the string data too long, causing the displayed table to be arranged in an untidy format, which is to be displayed after processing a string that is too long in the table.
Method One: (Other blogs See the method)
JS Method:
<script type= "Text/javascript" >
Jquery.fn.limit=function () {
var self = $ (".Table TR TD");
Self.each (function () {
var objstring = $ (this). text ();
var objlength = $ (this). Text (). length;
var num = 5;//$ (this). attr ("limit");
if (Objlength > num) {
$ (this). attr ("title", objstring);
Objstring = $ (this). Text (objstring.substring (0,num) + "...");
}
})
}
$ (function () {
Call Method:
$(". Table TR TD"). limit ();
The. Table TR TD is the control that is applied to, or $ ("#clazzTd") If it is id= "CLAZZTD". Limit ();
$ (document.body). limit ();
});
<script >
JSP calls:
<div id= "CLAZZTD" limit= "ten" > page gets the string data too long, resulting in the displayed table arrangement is not neat </div>
Table Call:
<table>
<tr>
<td> page Gets the string data too long, causing the displayed table to be arranged neatly </td>
</tr>
</table>
---------------------------------------------------------------------------------------
Special cases
When a table is added via jquery, the first method has no effect, regardless of whether the ID or the class attribute or the label's truncation of the long string is forexample.
The first method is only for the case or through tags (<c:foreach> <tr><td>33333444 </td> </tr></foreach> The rows that are added to the page are valid.
Comparison chart:
The first line is valid for other additions through jquery append without effect.
----------------------------------------------------------------------------------------------------
Method Two:
JS Method:
/**
* @param string
* @returns
* Truncated long strings
*/
function Sublimit (String)
{
var objlength =string.length;
var num = 20;
if (Objlength > num) {
String=string.substring (0,num) + "...";
}
alert (string);
return string;
}
In the jquery method:
var tr= "<tr><td title= '" +res.code+ ">"
+ Sublimit (Res.code)
+ "</td> <td title= '" +res.cname+ ">"
+ Sublimit (res.cname)
+ "</td> <td title= '" +res.hosts+ ">"
+ Sublimit (res.hosts)
+ "</td> <td title= '" +res.clazz+ ">"
+ Sublimit (res.clazz)
+ "</td> <td title= '" +res.handlerclazz+ ">"
+ Sublimit (res.handlerclazz)
+ "</td> <td title= '" +res.extend+ ">"
+ Sublimit (res.extend)
+ "</td>"
+ "<td><a class= ' A_model a_collect ' Href=javascript:openupdatemodal ('" +res.code+ "', '" +res.cname+ "', '" + Res.hosts+ "', '" +res.clazz+ "', '" +res.handlerclazz+ "', '" +res.extend+ "') > Modify </a> " +
"<a class= ' a_track ' Href=javascript:delresource ('" +res.code+ "') > Delete </a></td> </tr>";
$ (". Table"). Append (tr);
Explain:
Sublimit (Res.extend) is called method to intercept the parameters and return the truncated string;
Title= ' "+res.cname+" ', the Title property is the full string displayed when the mouse is moved over the string.
For example:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
jquery-truncation of long strings