如何防止 jQuery Droppable 接受某些 Draggable?
我正在创建一个包含可放置小部件“组”的页面,并且每个可拖动对象只能放置在一组可放置对象上。
我能够通过以下代码实现这一目标:
$("div.droppable").droppable({
//accept: ".draggable",
accept: function (draggable) {
if ($(this).attr("question_id") != null) {
if ($(this).attr("question_id") == draggable.attr("question_id")) return true;
}
return false;
});
但是,现在我遇到了一些麻烦。放置后,我无法像以前一样在同一组中的可放置对象周围移动可拖动对象。我可以将它放在一个 droppable 上一次,然后将其移动到另一个 droppable,但我无法将其移回第一个 droppable。
有谁知道会发生什么?任何意见将不胜感激。
I'm creating a page with "groups" of droppable widgets, and each draggable can only be dropped on one group of droppables.
I was able to achieve this by the following code:
$("div.droppable").droppable({
//accept: ".draggable",
accept: function (draggable) {
if ($(this).attr("question_id") != null) {
if ($(this).attr("question_id") == draggable.attr("question_id")) return true;
}
return false;
});
However, now I'm having a little trouble. After dropping, I was not able to move the draggable around droppables in the same group as I could before. I could drop it on a droppable once, move it to another, but I couldn't move it back to the first droppable.
Does anyone know what could have happened? Any input would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不知道你的代码出了什么问题。我创建了这个在 jsFiddle 上的测试用例,它按预期工作。如本测试用例所示,我使用
.data
来检索问题 ID。我希望这有帮助!
No idea what failed in your code. I created this test case on jsFiddle that is working as expected. As seen in this test case, I am using
.data
to retrieve the question ID.I hope this helps!