【发布时间】:2015-07-10 12:07:28
【问题描述】:
在 jquery-ui 文档中它说 out: 函数是在将接受的可拖动对象拖出可放置对象时触发的。但在我的情况下,我希望容器都是可拖放的。另外,我希望 id 为 droppable 的 div 也可以排序。现在拖放工作正常,但是当我拖出其中一项时,不会触发 out 功能,所以我该怎么做。
html
<div id="droppable" class="draggable droppable sortable">
</div>
<div id="draggable" class="droppable draggable sortable">
<p id="hello11" class="item">Hello1</p>
<p id="hello22" class="item">Hello2</p>
<p id="hello33" class="item">Hello3</p>
<p id="hello44" class="item">Hello4</p>
<p id="hello55" class="item">Hello5</p>
</div>
<div id="form-container">
<form method="post" action="">
<!-- Do stuff here -->
<input type="text" id ="hello1" name="xoxo1" value="">
<input type="text" id ="hello2" name="xoxo2" value="">
<input type="text" id ="hello3" name="xoxo3" value="">
<input type="text" id ="hello4" name="xoxo4" value="">
<input type="text" id ="hello5" name="xoxo5" value="">
</form>
</div>
script.js
jQuery(document).ready(function($){
$( ".droppable" ).droppable({
accept: ".item"
});
$( "#droppable" ).droppable({
accept: ".item",
drop: function( event, ui ) {
// Set values
var myid = ui.draggable.attr("id").toString();
myid = myid.substring(0, myid.length - 1);
document.getElementById(myid).value = myid;
},
out: function(event,ui){
// Unset the values
var myid = ui.draggable.attr("id").toString();
myid = myid.substring(0, myid.length - 1);
document.getElementById(myid).value = '';
}
});
$( ".sortable" ).sortable();
$( ".draggable .item" ).draggable({
connectToSortable: ".sortable"
});
});
【问题讨论】:
-
你会为此提供小提琴吗?
-
对不起,我在 jsfiddle 上没有这个,我正在本地机器上工作。 @ParagBhayani
-
你用的是什么可拖拽的插件?
-
请更新这个小提琴,以便我可以帮助你...jsfiddle.net/3eefs2kp
-
我正在使用 jQuery ui 。好的,我会注册 jsfiddle 并告诉你
标签: javascript jquery jquery-ui jquery-ui-droppable