我正在尝试创建一个从
ui.slider开始的jQuery小部件.我想要一个在’slide’事件上执行的自定义方法.我尝试覆盖父选项,就像正常使用滑块小部件一样,但我遇到了变量范围的问题:
$.widget( "ui.myslider",$.ui.slider,{ _create: function() { this.foo = "bar"; // Outputs "bar" this._mySlide(); // Outputs "undefined" when triggered this.options.slide = this._mySlide; $.ui.slider.prototype._create.apply(this,arguments); },_mySlide: function() { alert(this.foo); } }
编辑:
链接到ui.slider来源:https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.slider.js
编辑:解决方案
$.widget( "ui.myslider",{ _create: function() { $.ui.slider.prototype._create.apply(this,arguments); this.foo = "bar"; },_slide: function() { $.ui.slider.prototype._slide.apply(this,arguments); alert(this.foo); } }
解决方法
原文地址:https://www.jb51.cc/jquery/150389.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。