jQuery Drop-Down 自訂下拉框

來源:互聯網
上載者:User

標籤:

 線上執行個體

執行個體示範

使用方法
  1.  <section class="main">
  2.         <div class="wrapper-demo">
  3.             <div id="dd" class="wrapper-dropdown-1" tabindex="1">
  4.                 <span>手冊網</span>
  5.                 <ul class="dropdown" tabindex="1">
  6.                     <li><a href="#">jQuery特效</a></li>
  7.                     <li><a href="#">網站模板</a></li>
  8.                 </ul>
  9.             </div>
  10.             </div>
  11.     </section>
  12. </div>
  13. <script type="text/javascript" src="http://libs.useso.com/js/jquery/1.7.2/jquery.min.js"></script>
  14. <script type="text/javascript">
  15.     function DropDown(el) {
  16.         this.dd = el;
  17.         this.placeholder = this.dd.children(‘span‘);
  18.         this.opts = this.dd.find(‘ul.dropdown > li‘);
  19.         this.val = ‘‘;
  20.         this.index = -1;
  21.         this.initEvents();
  22.     }
  23.     DropDown.prototype = {
  24.         initEvents: function() {
  25.             var obj = this;
  26.             obj.dd.on(‘click‘, function(event) {
  27.                 $(this).toggleClass(‘active‘);
  28.                 return false;
  29.             });
  30.             obj.opts.on(‘click‘, function() {
  31.                 var opt = $(this);
  32.                 obj.val = opt.text();
  33.                 obj.index = opt.index();
  34.                 obj.placeholder.text(‘Gender: ‘ + obj.val);
  35.             });
  36.         },
  37.         getValue: function() {
  38.             return this.val;
  39.         },
  40.         getIndex: function() {
  41.             return this.index;
  42.         }
  43.     }
  44.     $(function() {
  45.         var dd = new DropDown($(‘#dd‘));
  46.         $(document).click(function() {
  47.             $(‘.wrapper-dropdown-1‘).removeClass(‘active‘);
  48.         });
  49.     });
  50. </script>
複製

 

下載

 

jQuery Drop-Down 自訂下拉框

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.