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;
}
});