jquery plug-in development notes_jquery
May 16, 2016 pm 06:20 PMToday 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) "<span id='" opt.fillid "'>" opt.fill "<span>";
}
$(this ).html(showbody);
}
this.limit(opt.limit);
return this;
}
});

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use the flash sale plug-in of PHP Developer City

Develop custom WordPress plugins using PHP

How to use JavaScript to develop debugging tools and plug-ins

Detailed explanation of PHP underlying development principles: plug-in development and extension mechanism implementation

How to add backup and restore functionality to WordPress plugin

Development and debugging of Vue statistical chart plug-in

Experience and advice from advanced Java developers: How to extend application functionality

How to use PHP to develop extensions in CMS
