Javascript jquery ui输出:函数未触发
在jQueryUI文档中,它说,out:函数是在接受的可拖动对象从可拖放对象中拖动时触发的。但在我的例子中,我希望容器既可以拖拽也可以放下。另外,我希望id为Dropable的div也可以排序。目前,拖放工作正常,但当我拖出其中一个项目时,不会触发out功能,因此如何才能做到这一点 htmlJavascript jquery ui输出:函数未触发,javascript,jquery,jquery-ui,jquery-ui-droppable,Javascript,Jquery,Jquery Ui,Jquery Ui Droppable,在jQueryUI文档中,它说,out:函数是在接受的可拖动对象从可拖放对象中拖动时触发的。但在我的例子中,我希望容器既可以拖拽也可以放下。另外,我希望id为Dropable的div也可以排序。目前,拖放工作正常,但当我拖出其中一个项目时,不会触发out功能,因此如何才能做到这一点 html <div id="droppable" class="draggable droppable sortable"> </div> <div id="draggable" cla
<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>
看起来您试图做的是两个连接的排序表,它已经由
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;
}
});
您能提供小提琴吗?对不起,我在JSFIDLE上没有小提琴,我正在本地机器上工作@ParagBhayaniwhat Dragable Dropable plugin您正在使用?请更新此提琴,以便我可以帮助您。。。我正在使用jQueryUI。好的,我将注册jsfiddle,让您知道您所做的非常棒,拖动功能变得非常平滑。隐马尔可夫模型。。。不完全是我想要的,但是我从你的答案中得到了改变我最初方法的想法。我真的很感谢你的回答。非常感谢。
$(".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;
}
});