JQuery1.5体验。二。MenuButton。

根据http://www.jankoatwarpspeed.com/post/2009/07/28/reinventing-drop-down-with-css-jquery.aspx

 

简单的写了一个MenuButton类……满足基本需求吧……不要太苛刻嘛·~

 

注:本代码并没有涉及到css,有兴趣者请去源网站去扒css吧~

 

// items:内容,格式为{} // container:节点ID // defaultValue: 初始值 // width: 下拉菜单高度 // onCommand:选择后的返回函数 var MenuButton = $.Class(); $.extend(MenuButton.prototype, { options: { items: null, container: "", onCommand: null }, setOptions: function (options) { $.extend($.extend(this, this.options), options); }, initialize: function (options) { this.setOptions(options); this.initializeDOM(); this.initializeEvent(); }, initializeDOM: function () { this.value = this.defaultValue; this.items = this.items || {}; this.container = $("#" + this.container); this.render(); }, initializeEvent: function () { this.header.click(function () { this.body.toggle(1000); } .proxy(this)); this.region.find("dd ul li a").click(function (e) { var clicked = $(e.target); this.header.html(clicked.html()); this.body.hide(); this.value = clicked.find("span.value").html(); this.onCommand && this.onCommand(this.value); } .proxy(this)); this.onWindowClickHandler = this.onWindowClick.proxy(this); $(document).bind('click', this.onWindowClickHandler); }, destroyDOM: function () { this.body = null; this.header = null; this.container = null; }, destroyEvent: function () { $(document).unbind('click', this.onWindowClickHandler); }, closed: function () { this.destroyEvent(); this.destroyDOM(); }, onWindowClick: function (e) { var clicked = $(e.target); if (!clicked.parents().filter(this.container).length) { this.body.hide(); } }, //构建选项 render: function () { var n = this.items[this.value] || "无选项"; var v = this.value || ""; this.region = $('<dl class="dropdown"></dl>'); this.container.append(this.region); this.region.append('<dt><a href="#" mce_href="#">' + n + '<span class="value">' + v + '</span></a></dt>'); this.region.append('<dd><ul></ul></dd>'); this.body = this.region.find("dd ul").css({ width: this.width }); this.header = this.region.find("dt a"); $.each(this.items, function (value, name) { this.body.append('<li><a href="#" mce_href="#">' + name + '<span class="value">' + value + '</span></a></li>'); } .proxy(this)); }, //获取选项值 getValue: function () { return this.value; }, //返回默认选项 resetValue: function () { this.setValue(this.defaultValue); }, //设定选项值 setValue: function (value) { var n = this.items[value] || "无选项"; var v = value || ""; this.header.html(n + '<span class="value">' + v + '</span>'); this.value = value; } }); 

 

于是你你你就有了this……

 

 

转载于:https://www.cnblogs.com/J2EEPLUS/archive/2011/02/18/2487797.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值