我有一个这样的对象:
function ImageHolder(Attributes, Parent)
{
this.Id = Attributes['Id'];
this.Parent = Parent;
this.Element = $('<div/>');
this.msg = "hello world";
this.Parent.append(this.Element);
this.handleDrop = function(e, ui)
{
alert(this.msg);
};
this.Element.droppable({drop: this.handleDrop});
}
然后我创建一个这样的对象:
holder = new ImageHolder(A,B);
但是当我尝试将一些东西放到元素上时,我得到了这个错误:
this.msg is undefined
我是不是做错了什么?
最佳答案
复制一份;
var thisCopy = this;
在下面的函数之前,然后像这样替换...
this.handleDrop = function(e, ui)
{
alert(thisCopy.msg);
};
关于javascript - JQuery droppable() 无法识别 "this"对象引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10121406/