The JQERYlimittext plug-in adds a display more function for long content. adds a display more function. attaches the code: Use the instance in the attachment.
The Code is as follows:
/**
* Demo:
* 1. $ ("# limittext"). limittext ();
* 2. $ ("# limittext"). limittext ({"limit": 1 });
* 3. $ ("# limittext "). limittext ({"limit": 1, "fill ":"...... "," morefn ": {" status ": true }});
* 4. $ ("# limittext "). limittext ({"limit": 1, "fill ":"...... "," morefn ": {" status ": true," moretext ":" more "," lesstext ":" hidden part "," fullfn ": function () {alert ("more")}, "lessfn": function () {alert ("less ")}}})
* 5. $ ("# limittext "). limittext ({"limit": 1, "fill ":"...... "," morefn ": {" status ": true }}). limit ("all ");
* @ Param {Object} opt
*{
* Limit: 30, // Number of displayed texts
* Fill: '...' // The text filled in when hidden
* Morefn :{
* Status: false, // whether to enable more
* Moretext: "(more)", // hide the text displayed when some text is hidden.
* Lesstext: "(less)", // The text displayed when all texts are displayed.
* Cssclass: "limittextclass", // enable the CSS class name for more A labels
* Lessfn: function () {}, // callback function when the text is less displayed
* Fullfn: function () {}// callback function when the text is more
*}
* @ Author Lonely
* @ Link http://www.liushan.net
* @ Version 0.2
*/
JQuery. fn. extend ({
Limittext: function (opt ){
Opt = $. extend ({
"Limit": 30,
"Fill ":"..."
}, Opt );
Opt. morefn = $. extend ({
"Status": false,
"Moretext": "(more )",
"Lesstext": "(less )",
"Cssclass": "limittextclass ",
"Lessfn": function (){
},
"Fullfn": function (){
}
}, Opt. morefn );
Var othis = this;
Var $ this = $ (othis );
Var body = $ this. data ('body ');
If (body = null ){
Bodydomainthis.html ();
$ This. data ('body', body );
}
Var getbuttom = function (showtext ){
Return "javasopt.morefn.css class +" '>"
+ Showtext
+ "";
}
This. limit = function (limit ){
If (body. length <= limit | limit = 'all '){
Var showbody = body + (opt. morefn. status? Getbuttom (opt. morefn. lesstext ):"");
} Else {
If (! Opt. morefn. status ){
Var showbody = body. substring (0, limit)
+ Opt. fill;
} Else {
Var showbody = body. substring (0, limit)
+ Opt. fill
+ Getbuttom (opt. morefn. moretext );
}
}
Export this.html (showbody );
}
This. limit (opt. limit );
$ ("." Javasopt.morefn.css class). live ("click", function (){
If(((this).html () = opt. morefn. moretext ){
Showbody = body
+ Getbuttom (opt. morefn. lesstext );
Export this.html (showbody );
Opt. morefn. fullfn ();
} Else {
Othis. limit (opt. limit );
Opt. morefn. lessfn ();
}
});
Return this;
}
});
Packaging http://www.jb51.net/jiaoben/29345.html