我存储了一个jquery对象(html元素的集合),但是当我在另一个函数中引用该对象时,它返回为'undefined'!这里是我的代码:为什么我不能在回调中引用我的jQuery对象?
this.container = $('#slide-menu'), // The menu container (e.g. a UL)
this.items = this.container.find('.menu-item'); // The menu items (e.g. all li's)
this.links = this.items.find('.link'); // The menu links
this.getCurrent(); // Set the current menu-item
this.getPrev(); // Set the previous menu-item
this.getNext(); // Set the next menu-item
console.log(this.items); // !!! The items exist here !!!
// Setup the menu items click events:
this.items.bind('click', function(e) {
console.log(this.items); // !!! But not here !!! ???
e.preventDefault();
o = $(e.currentTarget); // Set jquery object
if (!o.hasClass('active')) { // Prevent action on current menu-item
this.items.find('.active').removeClass('active'); // Remove the current active menu-item
o.addClass('active'); // Set new active menu item
任何人都不会有为什么发生这种情况,因为它的驾驶我疯了,只要我能看到这不应该是可能的任何想法。 JavaScript是坏了?!嗯,你觉得怎么样?
Doh!是的,你是绝对正确的,菜鸟错误对不起。非常感谢!! – Chris
哈哈 - 是javascript坏了? > jk。再次感谢,现在工作! – Chris