JQuery 拖拽带选项卡的 drop 不会克隆节点
我尝试让以下代码工作,其中应克隆可选元素中的元素并将其附加到不同选项卡中的可排序元素。但是,来自 selectable 的节点根本不会被克隆,而是被删除并附加到 sortable 中。这是代码:
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2 /jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="ui-lightness/jquery-ui-1.8.15.custom.css">
<script type="text/javascript">
$(function() {
var $tabs = $('#tabs').tabs();
$( "#selectable" ).selectable();
$('li', '#selectable').draggable({
connectToSortable: '#sortable',
helper: 'clone',
revert: 'invalid'
});
var $tab_items = $('ul:first li', $tabs).droppable({
accept : '#selectable li',
hoverClass : 'ui-state-hover',
drop : function(event, ui) {
var $item = $(this);
var $list = $($item.find('a').attr('href')).find('.connectedSortable');
$tabs.tabs('select', $tab_items.index($item));
$(this).appendTo($list).show('slow');
}
});
$('#selectable, #sortable').disableSelection();
});
</script>
</head>
<body>
<div id="tabs">
<ul>
<li><a href="#tab-selectable">Tab1</a></li>
<li><a href="#tab-sortable">Tab2</a></li>
</ul>
<div id="tab-selectable">
<ul id="selectable">
<li id="e101" class="ui-state-default">Num 1</li>
<li id="e102" class="ui-state-default">Num 2</li>
<li id="e103" class="ui-state-default">Num 3</li>
<li id="e104" class="ui-state-default">Num 4</li>
<li id="e105" class="ui-state-default">Num 5</li>
</ul>
</div>
<div id="tab-sortable">
<ul id="sortable" class="connectedSortable ui-helper-reset">
</ul>
</div>
</div>
</div>
</body>
有什么想法吗?
I tried to get the following code working where an element from a selectable should be cloned and appended to a sortable in a different tab. However, the node from the selectable is not cloned at all but instead removed and appended to the sortable. Here's the code:
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2 /jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="ui-lightness/jquery-ui-1.8.15.custom.css">
<script type="text/javascript">
$(function() {
var $tabs = $('#tabs').tabs();
$( "#selectable" ).selectable();
$('li', '#selectable').draggable({
connectToSortable: '#sortable',
helper: 'clone',
revert: 'invalid'
});
var $tab_items = $('ul:first li', $tabs).droppable({
accept : '#selectable li',
hoverClass : 'ui-state-hover',
drop : function(event, ui) {
var $item = $(this);
var $list = $($item.find('a').attr('href')).find('.connectedSortable');
$tabs.tabs('select', $tab_items.index($item));
$(this).appendTo($list).show('slow');
}
});
$('#selectable, #sortable').disableSelection();
});
</script>
</head>
<body>
<div id="tabs">
<ul>
<li><a href="#tab-selectable">Tab1</a></li>
<li><a href="#tab-sortable">Tab2</a></li>
</ul>
<div id="tab-selectable">
<ul id="selectable">
<li id="e101" class="ui-state-default">Num 1</li>
<li id="e102" class="ui-state-default">Num 2</li>
<li id="e103" class="ui-state-default">Num 3</li>
<li id="e104" class="ui-state-default">Num 4</li>
<li id="e105" class="ui-state-default">Num 5</li>
</ul>
</div>
<div id="tab-sortable">
<ul id="sortable" class="connectedSortable ui-helper-reset">
</ul>
</div>
</div>
</div>
</body>
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过一个简单的 ui.draggable.clone() 终于成功了。
With a simple
ui.draggable.clone()
it finally worked.