这个问题与jQuery的UI有关。
任何人都可以举例说明如下:
这是我到目前为止所做的:
$(function() {
$("#sortable").sortable().droppable();
$("#sortable").disableSelection();
$("#drop").droppable({
accept: "#sortable li",
drop: function (evt, ui) {
var $destination = $(this);
ui.draggable.appendTo( $destination );
}
}).draggable();
});
我在这里创造了一个小提琴: http://jsfiddle.net/eEJHb/1/
我遇到的问题: A)我无法将可排序的内容放入容器中 B)进入容器后,我需要将元素拖回到可排序列表
感谢您的帮助!
更新** 我的问题的一部分在选项“connectWith”中撒谎。它根本不起作用。相反,我使用了选项“connectToSortable”(作为draggable中的一个选项),我能够将可排序和可拖动的工作放在一起。
答案 0 :(得分:4)
在找到this
之前,我遇到了同样的问题
$(function () {
$("#timetable .items").sortable({
connectWith: "ul"
});
$("ul[id^='available']").draggable({
helper: "clone",
connectToSortable: ".items"
});
});
<style type="text/css">
.bar {
width: 100px;
height: 20px;
margin: 2px;
border: 1px solid black;
background-color: lightgreen;
text-align: center;
float: left;
margin: 2px;
padding: 2px;
cursor: pointer;
border-radius: 3px;
}
.list {
background-color: lightblue;
border: 1px solid gray;
}
.items .ui-selected {
background: red;
color: white;
font-weight: bold;
}
.items {
list-style-type: none;
margin: 0;
padding: 0;
width: 100px;
}
.items li {
margin: 2px;
padding: 2px;
cursor: pointer;
border-radius: 3px;
}
.weekday {
float: left;
}
.availablelist {
background-color: orange;
display: inline;
}
</style>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script type="text/javascript" src="http://www.pureexample.com/js/lib/jquery.ui.touch-punch.min.js"></script>
<div style="float:left;width:500px;">
<div>Available employee</div>
<ul id="available1" class="items">
<li class="list availablelist">Jhonny</li>
</ul>
<ul id="available2" class="items">
<li class="list availablelist">Tim</li>
</ul>
<ul id="available3" class="items">
<li class="list availablelist">George</li>
</ul>
<ul id="available4" class="items">
<li class="list availablelist">Melissa</li>
</ul>
<ul id="available5" class="items">
<li class="list availablelist">Alice</li>
</ul>
</div>
<div style="clear:both"></div>
<div id="timetable" style="float:left;width:700px;">
<div style="text-align:center">Time table</div>
<div class="weekday">Monday
<ul class="items">
<li class="list">Jhonny</li>
<li class="list">Tim</li>
<li class="list">George</li>
<li class="list">Melissa</li>
<li class="list">Alice</li>
</ul>
</div>
<div class="weekday">Tuesday
<ul class="items">
<li class="list">Jhonny</li>
<li class="list">Tim</li>
<li class="list">George</li>
<li class="list">Melissa</li>
<li class="list">Alice</li>
</ul>
</div>
<div class="weekday">Wednesday
<ul class="items">
<li class="list">Jhonny</li>
<li class="list">Tim</li>
<li class="list">George</li>
<li class="list">Melissa</li>
<li class="list">Alice</li>
</ul>
</div>
<div class="weekday">Thursday
<ul class="items">
<li class="list">Jhonny</li>
<li class="list">Tim</li>
<li class="list">George</li>
<li class="list">Melissa</li>
<li class="list">Alice</li>
</ul>
</div>
<div class="weekday">Friday
<ul class="items">
<li class="list">Jhonny</li>
<li class="list">Tim</li>
<li class="list">George</li>
<li class="list">Melissa</li>
<li class="list">Alice</li>
</ul>
</div>
<div class="weekday">Saturday
<ul class="items">
<li class="list">Jhonny</li>
<li class="list">Tim</li>
<li class="list">George</li>
<li class="list">Melissa</li>
<li class="list">Alice</li>
</ul>
</div>
<div class="weekday">Sunday
<ul class="items">
<li class="list">Jhonny</li>
<li class="list">Tim</li>
<li class="list">George</li>
<li class="list">Melissa</li>
<li class="list">Alice</li>
</ul>
</div>
</div>
答案 1 :(得分:0)
我建议您查看此文档:
http://jqueryui.com/sortable/#connect-lists
http://jqueryui.com/draggable/#sortable
以及这些问题的答案:
Getting jQuery sortable, droppable and draggable to work together
答案 2 :(得分:-2)
您可以使用jquery-ui中的交互。它提供可拖动和可排序的交互。