1. \r\n \r\n  \r\n   
      2. 選項(xiàng)1<\/a><\/li>\r\n   
      3. 選項(xiàng)2<\/a><\/li>\r\n   
      4. 選項(xiàng)3<\/a><\/li>\r\n  <\/ul>\r\n  作者:ghostwu(1)\r\n   

        博客: http:\/\/www.miracleart.cn\/ghostwu\/<\/p>\r\n  <\/p>\r\n  作者:ghostwu(2)\r\n   

        博客: http:\/\/www.miracleart.cn\/\/ghostwu\/<\/p>\r\n  <\/p>\r\n  作者:ghostwu(3)\r\n   

        博客: http:\/\/www.miracleart.cn\/\/ghostwu\/<\/p>\r\n  <\/p>\r\n <\/p>\r\n<\/body>\r\n<\/html><\/pre>

        tab2.js file<\/p>

        <\/p>

        ;(function ($) {\r\n $.fn.tabs = function (opt) {\r\n  var def = { evType: \"click\" }; \/\/定義了一個(gè)默認(rèn)配置\r\n  var opts = $.extend({}, def, opt);\r\n  var obj = $(this);\r\n\r\n  $(\"ul li:first\", obj).addClass(\"active\");\r\n  obj.children(\"p\").hide();\r\n  obj.children(\"p\").eq(0).show();\r\n\r\n  $(\"ul li\", obj).bind(opts.evType, function () {\r\n   $(this).attr(\"class\", \"active\").siblings(\"li\").attr(\"class\",\"\");\r\n   var id = $(this).find(\"a\").attr(\"href\").substring(1);\r\n   obj.children(\"p\").hide();\r\n   $(\"#\" + id, obj).show();\r\n  });\r\n };\r\n})(jQuery);<\/pre>

        1, a self-executing function that encapsulates the plug-in into a module and converts the jQuery object Pass to the formal parameter $<\/p>\n

        2, line 3, to define a default configuration, the trigger type of the tab, the default is click event <\/p>\n

        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 <\/p>\n

        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 <\/p>\n

        5, lines 11-16, in yellow, and click the corresponding tab. , let the corresponding p show and hide<\/p>\n

        Related recommendations:
        <\/p>\n

        About JavaScript plug-in Tab effect sharing<\/a><\/p>\n

        implementation WeChat applet with tab function<\/a><\/p>\n

        JS+jQuery example of writing a simple tab<\/a><\/p>"}

        国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

        Home Web Front-end JS Tutorial Sharing of tab production technology for jquery plug-in development

        Sharing of tab production technology for jquery plug-in development

        Dec 29, 2017 pm 05:53 PM
        jquery make Options

        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(&#39;hello,welcome to study jquery plugin dev&#39;);
          }
          // $.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( &#39;ghostwu&#39; );
          }
          $.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="點(diǎn)我">

        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: &#39;&#39;;
           display: block;
           clear: both;
           height: 0;
           visibility: hidden;
          }
         </style>
         <script src="tab2.js"></script>
         <script>
          $(function(){
           $("#tab").tabs( { evType : &#39;mouseover&#39; } );
          });
         </script>
        </head>
        <body>
         <p id="tab">
          <ul class="clearfix">
           <li><a href="#tab1">選項(xiàng)1</a></li>
           <li><a href="#tab2">選項(xiàng)2</a></li>
           <li><a href="#tab3">選項(xiàng)3</a></li>
          </ul>
          <p id="tab1">作者:ghostwu(1)
           <p>博客: http://www.miracleart.cn/ghostwu/</p>
          </p>
          <p id="tab2">作者:ghostwu(2)
           <p>博客: http://www.miracleart.cn//ghostwu/</p>
          </p>
          <p id="tab3">作者:ghostwu(3)
           <p>博客: http://www.miracleart.cn//ghostwu/</p>
          </p>
         </p>
        </body>
        </html>

        tab2.js file


        ;(function ($) {
         $.fn.tabs = function (opt) {
          var def = { evType: "click" }; //定義了一個(gè)默認(rèn)配置
          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!

        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 AI Tools

        Undress AI Tool

        Undress AI Tool

        Undress images for free

        Undresser.AI Undress

        Undresser.AI Undress

        AI-powered app for creating realistic nude photos

        AI Clothes Remover

        AI Clothes Remover

        Online AI tool for removing clothes from photos.

        Clothoff.io

        Clothoff.io

        AI clothes remover

        Video Face Swap

        Video Face Swap

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

        Hot Tools

        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)

        Hot Topics

        PHP Tutorial
        1502
        276
        How to use PUT request method in jQuery? How to use PUT request method in jQuery? Feb 28, 2024 pm 03:12 PM

        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

        jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

        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: &lt

        Use jQuery to modify the text content of all a tags Use jQuery to modify the text content of all a tags Feb 28, 2024 pm 05:42 PM

        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:

        Specific method to create film movement effect in PPT Specific method to create film movement effect in PPT Mar 26, 2024 pm 04:00 PM

        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

        Understand the role and application scenarios of eq in jQuery Understand the role and application scenarios of eq in jQuery Feb 28, 2024 pm 01:15 PM

        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

        Introduction to how to add new rows to a table using jQuery Introduction to how to add new rows to a table using jQuery Feb 29, 2024 am 08:12 AM

        jQuery is a popular JavaScript library widely used in web development. During web development, it is often necessary to dynamically add new rows to tables through JavaScript. This article will introduce how to use jQuery to add new rows to a table, and provide specific code examples. First, we need to introduce the jQuery library into the HTML page. The jQuery library can be introduced in the tag through the following code:

        How to tell if a jQuery element has a specific attribute? How to tell if a jQuery element has a specific attribute? Feb 29, 2024 am 09:03 AM

        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

        How to make a word cover How to make a word cover Mar 19, 2024 pm 06:50 PM

        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?

        See all articles