gpt4 book ai didi

javascript - jQuery Draggable 只允许拖动 1 个图像

转载 作者:行者123 更新时间:2023-11-30 18:39:45 25 4
gpt4 key购买 nike

我的页面上全是图片,准确地说是专辑封面。我添加了代码以使其可拖动,它只允许我拖动页面上的第一张图片。

这是为什么?

 $(document).ready(function () {
$("#draggable").each(function () {
$(this).draggable({
revert: function (dropped) {
var dropped = dropped && dropped[0].id == "droppable";
if (!dropped);
return !dropped;
}
});
});

$("#droppable").droppable({
drop: function (event, ui) {
var AlbumToAdd = ui.draggable.data("id");
if (AlbumToAdd != '') {
// Perform the ajax post
$.post("/ShoppingCart/DragToCart", { "id": AlbumToAdd },
function (data) {
// Successful requests get here
// Update the page elements
$('#cart-total').text(data.CartTotal);
});
}
}
});

});

如果您需要查看更多代码,请发表评论

最佳答案

通常 id 应该是唯一的。所以做 $("#draggable").each... 通常不是一个好习惯。将其更改为类选择器应该可以解决问题。

所以将其转化为:

$(".draggable").each(function () { ...

将你的html放入

<div class="draggable" class="ui-widget-content">
<p>Drag me around</p>
</div>

你可以看到我的工作示例(简化)here .

关于javascript - jQuery Draggable 只允许拖动 1 个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7203519/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com