Home Web Front-end JS Tutorial jquery plug-in development notes_jquery

jquery plug-in development notes_jquery

May 16, 2016 pm 06:20 PM
Plug-in development

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)

Copy code The code is as follows:

/**
* 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;
}
});
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use the flash sale plug-in of PHP Developer City How to use the flash sale plug-in of PHP Developer City May 22, 2023 pm 11:31 PM

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

Develop custom WordPress plugins using PHP Develop custom WordPress plugins using PHP May 26, 2023 am 11:40 AM

Develop custom WordPress plugins using PHP

How to use JavaScript to develop debugging tools and plug-ins How to use JavaScript to develop debugging tools and plug-ins Jun 15, 2023 pm 12:35 PM

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 Detailed explanation of PHP underlying development principles: plug-in development and extension mechanism implementation Sep 09, 2023 am 09:25 AM

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

How to add backup and restore functionality to WordPress plugin How to add backup and restore functionality to WordPress plugin Sep 05, 2023 pm 07:09 PM

How to add backup and restore functionality to WordPress plugin

Development and debugging of Vue statistical chart plug-in Development and debugging of Vue statistical chart plug-in Aug 17, 2023 pm 04:06 PM

Development and debugging of Vue statistical chart plug-in

Experience and advice from advanced Java developers: How to extend application functionality Experience and advice from advanced Java developers: How to extend application functionality Nov 23, 2023 am 08:08 AM

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

How to use PHP to develop extensions in CMS How to use PHP to develop extensions in CMS Jun 21, 2023 am 09:08 AM

How to use PHP to develop extensions in CMS

See all articles