如何将ondragstart =“drag(event)”添加到动态创建的元素(img div)?

时间:2017-01-05 02:05:58

标签: javascript jquery

示例:

动态创建的图片:

var newImg = document.createElement('img');
newImg.setAttribute('id', newimage);

如何为此图像提供属性“ondragstart =”drag(event)“”?

感谢。

1 个答案:

答案 0 :(得分:0)

使用addEventListener添加活动

public override void PrepareForSegue(NSStoryboardSegue segue, NSObject sender)
{
    base.PrepareForSegue(segue, sender);

    switch (segue.Identifier)
    {
        case "UserLoginSegue":
            UserLoginController loginSheet = segue.DestinationController as UserLoginController;
            var theView = loginSheet.View;
            loginSheet.Username = "";
            loginSheet.Password = "";
            loginSheet.Presentor = this;
            loginSheet.DialogAccepted += (object s, EventArgs e) => { Console.WriteLine("OK Clicked"); };
            loginSheet.DialogCanceled += (object s, EventArgs e) => { Console.WriteLine("Cancel Clicked"); };
            break;
    }
}

所以你的代码将是

target.addEventListener(type, listener)

该活动将通过。