Compile the jquery plugin (using the collapsed Panel as an example)
??
The recommended method for creating a jQuery plug-in is to first create a function that allows the use of the dollar sign ($. By default, dollar signs may conflict with other JavaScript frameworks. If you wrap the plug-in a function, there will be no conflict. We recommend that you use the following code to create the jQuery Plugin:
(Function ($) {$. fn. accordion = function () {// Add plug-in code};}) (jQuery );
In the above Code, the jQuery keyword is applied to the wrapper function, which allows you to use the dollar sign in the plug-in, just as when using the fn attribute. After the wrapper function is ready, you can use the dollar sign to replace the jQuery keyword in any part of the plug-in without interfering with other third-party plug-ins.
Plug-in code
(function($) { $.fn.accordion = function(options) { return this.each(function() { var dts = $(this).children('dt'); dts.click(onClick); dts.each(reset); }); function onClick() { $(this).siblings('dt').each(hide); if($(this).next().is(:hidden)){ $(this).next().slideDown('fast'); return false; } if($(this).next().is(:visible)){ $(this).next().slideUp('fast'); return false; } } function hide() { $(this).next().slideUp('fast'); } function reset() { $(this).next().hide(); } }})(jQuery);
Page code
<Script src = http://libs.baidu.com/jquery/1.9.0/jquery.js> </script> <script src = aa. js> </script> // plug-in js <script> $ (function () {// call your custom plug-in $ ('dl # my-accordion '). accordion (); // call ins}); </script>
-
Section 1
-
Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam.
-
Section 2
-
Vestibulum a velit eu ante scelerisque vulputate.
-
Section 3
-
Nam mi. Proin viverra leo ut odio. Curabitur malesuada.
-
Section 4
-
Vivamus nisi metus, molestie vel, gravida in, condimentum sit amet, nunc.
The effect is as follows:
This is what we want.