Draggables Jquery UI,禁用可放置的单个 div
我正在尝试制作一些教育网站,我想让学生做的一件事是将项目拖到一个区域,然后才能进入下一阶段。
我认为执行此操作的方法是使用 jquery droppables 脚本,并在将项目拖放到可放置 div 中时禁用可拖动选项。然后我将向变量添加 1,当它达到正确的数字时,将启用前进按钮。
问题是我无法弄清楚如何使可放置功能仅适用于每个特定的可拖动对象。所以我所拥有的是:
$(document).ready(function() {
$("#draggable").draggable();
$("#draggable2").draggable();
$("#droppable").droppable({
drop: function() { $( "#draggable" ).draggable( "option", "disabled", true );; }
});
});
有了这些 div;
<div id="droppable">Drop here</div>
<div id="draggable" class="drag">Drag me</div>
<div id="draggable2" class="drag">Drag me</div>
但当然,这一切所做的只是在将任何拖拽到可放置 div 中时禁用第一个可拖拽。我的 JavaScript 不是很好(正在学习),我不知道如何让它只禁用我放入可放置区域的 JavaScript。
有人可以帮忙吗?
I'm trying to make some educational site and one of the things I want to have the students do is drag items to an area before being able to proceed to the next stage.
I was thing the way to do this was use the jquery droppables script and have the items draggable option disable when it is dropped in the droppable div. Then I was going to add 1 to a variable, when it gets to the right number the button to advance would be enabled.
The problem is that I can't figure out how to make the droppable function work only for each particular draggable. So what I have is:
$(document).ready(function() {
$("#draggable").draggable();
$("#draggable2").draggable();
$("#droppable").droppable({
drop: function() { $( "#draggable" ).draggable( "option", "disabled", true );; }
});
});
With these divs;
<div id="droppable">Drop here</div>
<div id="draggable" class="drag">Drag me</div>
<div id="draggable2" class="drag">Drag me</div>
But of course, all this does is disable the the first draggable whenever any are dragged into the droppable div. My javascript is not very good (im learning) and I don't know how I would make it only disable the one that I put into the droppable area.
Can anyone help please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只是将正确的代码放在错误的位置。
上面的代码将独立工作,并关闭 #draggable 的可拖动功能,无需将其放在放置函数中。
或者:
两者都可以。
You're just putting the right code in the wrong place.
The above will work on it's own and turn off draggable for #draggable, no need to put it in the drop function.
OR:
Either will work.
这可以通过定义可拖动和可放置区域的
范围
来实现:示例链接。
This can be achieved by defining a
scope
to both draggables and droppable area:Example Link.