拖拽交换位置
程序员文章站
2022-07-14 16:21:36
...
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>拖拽交换位置</title>
<style type="text/css">
ul {
list-style-type: none;
margin: 0;
padding: 0;
margin-bottom: 10px;
}
li {
margin: 5px;
padding: 5px;
width: 150px;
border: 1px solid #eaeaea;
cursor: pointer;
}
li:hover{
box-shadow: 1px 2px 3px #eeeeee;
}
</style>
</head>
<body>
<ul>
<li id="draggable" class="ui-state-highlight">请拖拽我</li>
</ul>
<ul id="sortable">
<li class="ui-state-default">Item 1</li>
<li class="ui-state-default">Item 2</li>
<li class="ui-state-default">Item 3</li>
<li class="ui-state-default">Item 4</li>
<li class="ui-state-default">Item 5</li>
</ul>
</body>
</html>
<script src="js/jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery-ui.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function() {
$("#sortable").sortable({
revert: true
});
$("#draggable").draggable({
connectToSortable: "#sortable",
helper: "clone",//重复克隆
revert: "invalid"
});
$("ul, li").disableSelection();
});
</script>
需要引进jQuery-ui.js文件