Javascript drop上的jQuery未启动?
我正在尝试使用jqueryui在drop上执行一些Javascript drop上的jQuery未启动?,javascript,jquery,Javascript,Jquery,我正在尝试使用jqueryui在drop上执行一些 然而,无论我做什么,下降时的根本不会启动 我用来使div可拖放的代码如下: $(document).ready(function () { var x = null; //Make element draggable $(".drag").draggable({ helper: 'clone', cursor: 'move', tolerance: 'fit',
然而,无论我做什么,下降时的
根本不会启动
我用来使div可拖放的代码如下:
$(document).ready(function () {
var x = null;
//Make element draggable
$(".drag").draggable({
helper: 'clone',
cursor: 'move',
tolerance: 'fit',
stack: '.drag',
revert: "invalid"
});
$("#droppable").droppable({
drop: function (e, ui) {
if ($(ui.draggable)[0].id != "") {
x = ui.helper.clone();
ui.helper.remove();
x.draggable({
//helper: 'original',
containment: '#droppable',
tolerance: 'fit',
stack: '.drag'
});
x.resizable({
animate: true,
//aspectRatio: 16 / 9,
helper: "ui-resizable-helper",
handles: "n, e, s, w, nw, ne, sw,se"
});
x.appendTo('#droppable');
}
}
});
});
在drop上执行某些操作的代码如下:
$(".drag").on("drop", function(e, ui) {
//alert('selected');
var srcc=$(this).find('img').attr('src');
$('#droppable #thumbs #drag_trans img').attr('src',srcc);
});
我可以将拖放时的功能更改为正常单击或鼠标悬停事件
,代码工作正常,但当我在拖放时使用时,它将无法工作
有人能告诉我为什么on drop没有启动吗?无需添加额外的on drop
功能。看看这个。您可以在drop:function(e,ui){…}
代码段中进行更改。使用了以下JS代码:
$(document).ready(function () {
var x = null;
//Make element draggable
$(".drag").draggable({
helper: 'clone',
cursor: 'move',
tolerance: 'fit',
stack: '.drag',
revert: "invalid"
});
$("#droppable").droppable({
drop: function (e, ui) {
if ($(ui.draggable).attr('id') != "") {
x = ui.helper.clone();
ui.helper.remove();
x.draggable({
//helper: 'original',
containment: '#droppable',
tolerance: 'fit',
stack: '.drag'
});
x.resizable({
animate: true,
//aspectRatio: 16 / 9,
helper: "ui-resizable-helper",
handles: "n, e, s, w, nw, ne, sw,se"
});
x.appendTo('#droppable');
}
}
});
});
要使其工作,拖放时的必须位于可拖放的元素上。对于可拖动的元素,没有可用的drop
方法。然后您只需将函数更改为使用:$(“#droppable”)。在(“drop”上,函数(e,ui){…}
在drop:
函数中进行更改是可行的。但由于某些原因,它只会返回最后一个图像。我正在尝试在drop:functionvar srcc=$('this')中进行更改。查找('img')。attr('src');alert(srcc);
。有什么想法吗?你可以尝试使用$(ui.helper)
?