JQERYlimittext plug-in version 0.2 (long content restricted display) _ jquery

Source: Internet
Author: User
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
Related Article

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.