gpt4 book ai didi

jquery - 找到掉落的元素

转载 作者:行者123 更新时间:2023-12-01 06:32:47 24 4
gpt4 key购买 nike

我正在制作一个棋盘,并试图找到棋子掉落的表格元素。不幸的是,放置事件似乎根本没有触发。

https://jsfiddle.net/thwee3/hhxt84k1/

$('.piece').draggable();
$('.pieces').droppable({
drop: function(){
alert($(this).attr('id')); // should give me the number of the field
}
});

这就是我到目前为止所拥有的,有人可以告诉我为什么 drop 事件没有触发吗?

最佳答案

$(document).ready(function(){
$('.piece').draggable();
$('.field').droppable({
drop: function(){
alert($(this).attr('id'));
}
});
});

并将其添加到 css 中:

.field {
height:100%;
}

参见demo

关于jquery - 找到掉落的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41752624/

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