jquery ui 输出:函数未触发
jquery ui out: function not triggering
在 jquery-ui 文档中它说 out: 当接受的可拖动对象被拖出可放置对象时会触发函数。但就我而言,我希望容器都是可拖放的。我还希望带有 id droppable 的 div 也可以排序。现在拖放工作正常,但是当我拖出其中一个项目时,没有触发输出功能,所以我该怎么做。
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"
});
});
看起来您正在尝试做的是两个连接的排序表,sortable
小部件已经处理了。您有几乎相同的事件,drop
几乎等同于 receive
,并且 out
也有效。
还不完全清楚最终结果应该是什么,但这应该会给你一些想法:
$(".sortable").sortable({
connectWith: '.sortable',
receive: function (event, ui) {
// Set values
var myid = ui.item.attr("id").toString();
myid = myid.substring(0, myid.length - 1);
document.getElementById(myid).value = myid;
},
out: function (event, ui) {
// Unset the values
console.log('out')
var myid = ui.item.attr("id").toString();
myid = myid.substring(0, myid.length - 1);
document.getElementById(myid).value = myid;
}
});
在 jquery-ui 文档中它说 out: 当接受的可拖动对象被拖出可放置对象时会触发函数。但就我而言,我希望容器都是可拖放的。我还希望带有 id droppable 的 div 也可以排序。现在拖放工作正常,但是当我拖出其中一个项目时,没有触发输出功能,所以我该怎么做。
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"
});
});
看起来您正在尝试做的是两个连接的排序表,sortable
小部件已经处理了。您有几乎相同的事件,drop
几乎等同于 receive
,并且 out
也有效。
还不完全清楚最终结果应该是什么,但这应该会给你一些想法:
$(".sortable").sortable({
connectWith: '.sortable',
receive: function (event, ui) {
// Set values
var myid = ui.item.attr("id").toString();
myid = myid.substring(0, myid.length - 1);
document.getElementById(myid).value = myid;
},
out: function (event, ui) {
// Unset the values
console.log('out')
var myid = ui.item.attr("id").toString();
myid = myid.substring(0, myid.length - 1);
document.getElementById(myid).value = myid;
}
});