Sharing of tab production technology for jquery plug-in development
This article mainly introduces the tab production of jquery plug-in development in detail. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.
In jquery, common plug-in development methods include:
One is to extend a method for the $ function itself. This is a static extension (also called a class extension). This kind of plug-in is usually Tool method,
There is also one that extends on the prototype object $.fn. The developed plug-in is used on the dom element
1. Class level extension
$.showMsg = function(){ alert('hello,welcome to study jquery plugin dev'); } // $.showMsg();
Be careful to introduce the jquery library in advance. In the above example, a method showMsg is added to the $function, then it can be called with $.showMsg()
$.showName = function(){ console.log( 'ghostwu' ); } $.showName();
This kind of plug-in is relatively rare and is generally used to develop tool methods, such as $.trim, $.isArray(), etc. in jquery
2. Expand the function on $.fn.
This kind of plug-in is used on elements. For example, if I extend a function and click a button, the value of the current button will be displayed.
$.fn.showValue = function(){ return $(this).val(); } $(function(){ $("input").click(function(){ // alert($(this).showMsg()); alert($(this).showMsg()); }); }); <input type="button" value="点我">
Add a showValue method on $.fn to return the value of the current element. After obtaining the page input element and binding the event, you can call this method to display the button The value "click me" is commonly used in actual plug-in development. Next, we will use this extension mechanism to develop a simple tab plug-in:
Page layout and style:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <script src="https://cdn.bootcss.com/jquery/1.12.0/jquery.js"></script> <style> #tab { width:400px; height:30px; } #tab li, #tab ul { list-style-type:none; } #tab ul { width:400px; height: 30px; border-bottom:1px solid #ccc; line-height: 30px; } #tab ul li { float:left; margin-left: 20px; padding:0px 10px; } #tab ul li.active { background: yellow; } #tab ul li a { text-decoration: none; color:#666; } #tab p { width:400px; height:350px; background-color:#ccc; } .clearfix:after{ content: ''; display: block; clear: both; height: 0; visibility: hidden; } </style> <script src="tab2.js"></script> <script> $(function(){ $("#tab").tabs( { evType : 'mouseover' } ); }); </script> </head> <body> <p id="tab"> <ul class="clearfix"> <li><a href="#tab1">选项1</a></li> <li><a href="#tab2">选项2</a></li> <li><a href="#tab3">选项3</a></li> </ul> <p id="tab1">作者:ghostwu(1) <p>博客: http://www.php.cn/ghostwu/</p> </p> <p id="tab2">作者:ghostwu(2) <p>博客: http://www.php.cn//ghostwu/</p> </p> <p id="tab3">作者:ghostwu(3) <p>博客: http://www.php.cn//ghostwu/</p> </p> </p> </body> </html>
tab2.js file
;(function ($) { $.fn.tabs = function (opt) { var def = { evType: "click" }; //定义了一个默认配置 var opts = $.extend({}, def, opt); var obj = $(this); $("ul li:first", obj).addClass("active"); obj.children("p").hide(); obj.children("p").eq(0).show(); $("ul li", obj).bind(opts.evType, function () { $(this).attr("class", "active").siblings("li").attr("class",""); var id = $(this).find("a").attr("href").substring(1); obj.children("p").hide(); $("#" + id, obj).show(); }); }; })(jQuery);
1, a self-executing function that encapsulates the plug-in into a module and converts the jQuery object Pass to the formal parameter $
2, line 3, to define a default configuration, the trigger type of the tab, the default is click event
3, line 4, if opt passes the parameter, then Use the opt configuration, otherwise use the default configuration in line 3. The purpose of this line is to configure the plug-in’s representation without changing the plug-in source code
4, lines 7-9 , let the first p of the tab be displayed, and hide the rest. Add class='active' to the first tab. Highlight
5, lines 11-16, in yellow, and click the corresponding tab. , let the corresponding p show and hide
Related recommendations:
About JavaScript plug-in Tab effect sharing
implementation WeChat applet with tab function
JS+jQuery example of writing a simple tab
The above is the detailed content of Sharing of tab production technology for jquery plug-in development. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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

1. Start PPT, create a new blank document, select all text boxes and delete them. 2. Execute the Insert-Shape command, drag a rectangle in the document, and fill the shape with black. 3. Drag the rectangle to elongate it, execute the Insert-Shape command, drag out the small square, and set the fill color to white. 4. Copy and paste the small squares one by one so that the top and bottom are evenly distributed on both sides of the film. After selecting them all with ctrl+a, right-click and select Group. 5. Execute the Insert-Picture command, find the picture to be inserted in the pop-up dialog box, click to open, and adjust the size and position of the picture. 6. Repeat step 5 to insert and set the remaining pictures in order to form a film picture. 7. Select the film, execute animation-add animation command

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

A graduation thesis must have a cover, a table of contents, an end, etc. Only then can the thesis be complete. In the last issue, the editor has shared with friends how to make a table of contents in Word. In this issue, I will share with you how to make a word cover. If you don’t know how to make it, hurry up! 1. First, we open the word document we want to make a cover, as shown in the figure below: 2. Then, we click the [Chapter] button on the menu bar and select the cover page. This function is equivalent to a cover library, in which you can Choose a suitable and beautiful cover by yourself, as shown in the red circle in the picture below: 3. After clicking, you can see various types of covers, such as business type, suitable for company contracts and documents; resume type, suitable for job hunting and submission of resumes Friends, wait, okay?

When making PPT, using some animation effects will make it more lively and cute than without using animation effects. With the addition of animation effects, people may like to watch this PPT, so we must learn how to create animation effects for PPT. Next, I will introduce in detail how to add animation effects to PPT. Please continue reading and study these steps carefully. I believe they will be helpful to you! First, open the PPT we made ourselves. You will notice that this PPT currently does not have any animation effects (as shown by the red arrow in the picture below). 2. Then, we need to add animation effects to the picture. We first select the picture, and then click the [Animation] button on the menu bar (as shown in the red circle in the figure below). 3. Next, we click inside the animation

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s
