1

我有一个像这样的对象:

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

我在这里做错了吗?

4

1 回答 1

2

复印一份;

var thisCopy = this;

在以下功能之前,然后像这样替换......

this.handleDrop = function(e, ui)
{
    alert(thisCopy.msg);

};
于 2012-04-12T10:05:28.070 回答