Home  >  Article  >  Web Front-end  >  Write your own jQuery plug-in simple implementation code_jquery

Write your own jQuery plug-in simple implementation code_jquery

WBOY
WBOYOriginal
2016-05-16 18:07:39899browse

Here I only explain how to write your own plug-in. As for what functions you want to achieve, it depends on each person... Okay, let’s start...
jQuery plug-ins are mainly divided into three types
1. Encapsulating object methods Plug-ins
2. Plug-ins that encapsulate global functions
3. Plug-ins that extend selectors
Only the first two types are written here, which are the more common ones..
Most plug-ins are written in this form of:

Copy code The code is as follows:

(function ($) {
/ *Place code here*/
})(jQuery);

The advantage of this is that you can still use $ as an alias for jQuery inside the function without affecting the use of $ by other libraries
jQuery provides two extensions for writing plug-ins
$.fn.extend({}); for extending the first
$.extend({}); for extending the second
and below To achieve the effect screenshots and code
Write your own jQuery plug-in simple implementation code_jquery
Copy the code The code is as follows:


< ;html xmlns="http://www.w3.org/1999/xhtml">







  • 1

  • 2
  • ;li>3
  • 4

  • 5





Statement:
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