Mornin'全部.
我正在将原型代码重写为JQuery插件,并且不知道如何处理这个部分:
this.observers = events.map(function(name) {
var handler = this["on" + name.].bind(this);
this.element.observe(name, handler);
return { name: name, handler: handler };
}.bind(this));
Run Code Online (Sandbox Code Playgroud)
我结束了:
this.observers = $.each(events , function(i, name) {
var handler = "on"+name;
$element.live({
name: handler
});
}
Run Code Online (Sandbox Code Playgroud)
我完全错了?我不明白原型bind()的用途.
感谢帮助 !
编辑:上下文是一个插件init()函数,我附加"动态"事件和他们的处理程序编码为私有方法...
plugin.init = function() {
// the plugin's final properties are the merged default and user-provided options (if any)
plugin.settings = $.extend({}, defaults, options);
if (!plugin.observers) {
var events = ("mouseover mouseout").split(" ");
plugin.observers = $.map(events, $.proxy(function(name) { …Run Code Online (Sandbox Code Playgroud) Mornin'全部,
我有麻烦玩jQuery UI自动完成小部件事件.我想将一个自定义类添加到所选项的父级<li>.生成的标记如下所示:
<li class="result">
<a><span></span></a>
</li>
Run Code Online (Sandbox Code Playgroud)
当一个项目是焦点时,jQuery将该类添加.ui-state-hover到<a>
如何.selected向父类添加类<li>?我正试图从一个focus事件做到但我不知道如何访问父母<li>.我查看了jQuery UI的来源,找到了.ui-state-hover应用的位置和方式,但没有帮助.
这是我的自动完成代码.
/**
* Override the default behavior of autocomplete.data('autocomplete')._renderItem.
*
* @param ul _object_ The conventional ul container of the autocomplete list.
* @param item _object_ The conventional object used to represent autocomplete data.
* {value:'',label:'',desc:'',icon:''}
*/
var renderItemOverride = function (ul, item) {
return $('<li class="result"></li>')
.data("item.autocomplete", item)
.append('<a><span class="name">' + item.label + '</span><span …Run Code Online (Sandbox Code Playgroud)