从可拖动的img获取src [英] get src from draggable img
本文介绍了从可拖动的img获取src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这小段代码可拖动&放下图片:
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>');
}
});
想法是:当我拖动图像时,而不是显示虚拟图像,而是显示图像本身,但是我如何从可拖动的图像中获取src.有想法吗?
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?
谢谢.
推荐答案
尝试以下代码:
***
$('#mybox').droppable({
drop: function (event, ui ) {
$(this).append('<div style="float:left;"><img src="'+ ui.draggable.attr('src') +'"></div>');
}
});
***
这篇关于从可拖动的img获取src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文