jquery Plugin Development Notes _jquery

Source: Internet
Author: User
Today, I found out that JQ had a way of storing this temporary data:

$ ("Dom"). Data ("MyData", "This Is data"); There is the plug-in development when we often want to add methods to plug-ins, in fact, using JS internal method to add methods can

This.myfn=function () {}

The following is the source code for the previous plugin that displays part of the text:

(similar to CSS text-overflow, but this plugin you need to provide display a few words, for precise control display quantity)
Copy Code code as follows:

/**
* Demo:
* 1.$ ("#limittext"). Limittext ();
* 2.$ ("#limittext"). Limittext ({"Limit": 1});
* 3.$ ("#limittext"). Limittext ({"Limit": 1, "Fill": "(partially hidden)", "Fillid": "AAA"});
* 4.$ ("#limittext"). Limittext ({"Limit": 1, "Fill": "(partially hidden)", "Fillid": "AAA"}). Limit (10); * 5.$ ("#limittext"). Limittext ({"Limit": 1, "Fill": "(partially hidden)", "Fillid": "AAA"}). Limit (' all ');
* @param {Object} opt
* @author Lonely * @link http://liushan.net
*/
JQuery.fn.extend ({
Limittext:function (opt) {
Opt=$.extend ({
"Limit": 30,
"Fill": "...",
"Fillid": null
},OPT);
var $this =$ (this);
var body=$ (this). Data (' body ');
if (body==null) {
body= $this. html ();
$ (this). Data ("Body", body);
}
This.limit=function (limit) {
if (body.length<=limit| | limit== ' all ')
var showbody=body;
else{
if (opt.fillid==null)
var showbody=body.substring (0,limit) +opt.fill;
Else
var showbody=body.substring (0,limit) + "<span id= '" +opt.fillid+ "' >" +opt.fill+ "<span>";
}
$ (this). html (showbody);
}
This.limit (Opt.limit);
return this;
}
});

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.