jQuery Drop-Down 自定义下拉框
在线实例
使用方法
- <section class="main">
- <div class="wrapper-demo">
- <div id="dd" class="wrapper-dropdown-1" tabindex="1">
- <span>手册网</span>
- <ul class="dropdown" tabindex="1">
- <li><a href="#">jQuery特效</a></li>
- <li><a href="#">网站模板</a></li>
- </ul>
- </div>
- </div>
- </section>
- </div>
- <script type="text/javascript" src="http://libs.useso.com/js/jquery/1.7.2/jquery.min.js"></script>
- <script type="text/javascript">
- function DropDown(el) {
- this.dd = el;
- this.placeholder = this.dd.children('span');
- this.opts = this.dd.find('ul.dropdown > li');
- this.val = '';
- this.index = -1;
- this.initEvents();
- }
- DropDown.prototype = {
- initEvents: function() {
- var obj = this;
- obj.dd.on('click', function(event) {
- $(this).toggleClass('active');
- return false;
- });
- obj.opts.on('click', function() {
- var opt = $(this);
- obj.val = opt.text();
- obj.index = opt.index();
- obj.placeholder.text('Gender: ' + obj.val);
- });
- },
- getValue: function() {
- return this.val;
- },
- getIndex: function() {
- return this.index;
- }
- }
- $(function() {
- var dd = new DropDown($('#dd'));
- $(document).click(function() {
- $('.wrapper-dropdown-1').removeClass('active');
- });
- });
- </script>
复制
相关推荐
EdwardSiCong 2020-11-23
85477104 2020-11-17
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
momode 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28
tthappyer 2020-07-25
TONIYH 2020-07-22
tztzyzyz 2020-07-20
83510998 2020-07-18
81463166 2020-07-17