Today I discovered that JQ itself already has a way to store this temporary data:
$("dom").data("mydata","this is data"); Also, when we were developing plug-ins, we It is often necessary to add methods to plug-ins. In fact, just use the method of adding methods inside JS
this.myfn=function(){}
The source code of the previous plug-in that displays part of the text is given below. :
(Similar to CSS text-overflow, but for this plug-in you need to provide a few words to display to accurately control the number of displays)
/**
* demo:
* 1.$("#limittext").limittext();
* 2.$("#limittext").limittext({"limit":1});
* 3.$("#limittext").limittext({"limit":1,"fill":"( 免费最合)","fillid":"aaa"});
* 4.$("#limittext").limittext({"limit":1,"fill":"( 免费最合)","fillid":"aaa"}).limit(10); * 5.$("#limittext").limittext({"limit":1,"fill":"( 免费安全)","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) "" opt.fill "";
}
$(this ).html(showbody);
}
this.limit(opt.limit);
return this;
}
});