get src from draggable img

人盡茶涼 提交于 2019-12-25 03:14:06

问题


i have this little code to drag & drop images:

$("img").draggable({
    revert: true,
    opacity: 0.7,
    cursor: "move",
    cursorAt: {
        cursor: "crosshair",
        top: -5,
        left: -5
    }
});

$('#mybox').droppable({
    drop: function () {
        $(this).append('<div style="float:left;"><img src="http://dummyimage.com/42x40/000/fff.jpg"></div>');
    }
});

the idea is: when I drag a image, instead of show the dummy image, show the image itself, but how i can get the src from image from draggable. Any Idea?

Thanks in advance.


回答1:


Try this code:

***
$('#mybox').droppable({
    drop: function (event, ui ) {
        $(this).append('<div style="float:left;"><img src="'+ ui.draggable.attr('src') +'"></div>');
    }
});
***


来源:https://stackoverflow.com/questions/6170812/get-src-from-draggable-img

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!