Jquery-ui。使用“可拖动”、“可排序”和“选项卡”时遇到问题一起
我从此处这个有效的拖放示例开始。
然而,当我尝试将放置区域放置在选项卡中时,它效果很好(此处)它似乎打破了。当我尝试将项目放在“sortable 2”选项卡上时,它停止工作。
希望这是有道理的。
HTML 看起来像这样:
<ul>
<li id="draggable" class="ui-state-highlight">Drag me down</li>
</ul>
<div id="tabs">
<ul>
<li><a href="#tabs-1">Sortable 1</a></li>
<li><a href="#tabs-2">Sortable 2</a></li>
</ul>
<div id="tabs-1">
<div class="ui-state-default">Item 13</div>
<div class="ui-state-default">Item 23</div>
<div class="ui-state-default">Item 3</div>
<div class="ui-state-default">Item 4</div>
</div>
<div id="tabs-2">
<div class="ui-state-default">Item 1</div>
<div class="ui-state-default">Item 2</div>
<div class="ui-state-default">Item 3</div>
<div class="ui-state-default">Item 4</div>
</div>
</div>
和 JavaScript :
$("#tabs").tabs();
$("#tabs-1, #tabs-2").sortable({
revert: true
});
$("#draggable").draggable({
connectToSortable: '#tabs-1, #tabs-2',
helper: 'clone',
revert: 'invalid'
});
$("ul, li").disableSelection();
I started out with this working drag and drop example here.
It works great however when I try to place the drop regions within tabs(Here) it seem to break. It stops working when I try to drop an item on the "sortable 2" tab.
Hope this makes sense.
The HTML looks like this:
<ul>
<li id="draggable" class="ui-state-highlight">Drag me down</li>
</ul>
<div id="tabs">
<ul>
<li><a href="#tabs-1">Sortable 1</a></li>
<li><a href="#tabs-2">Sortable 2</a></li>
</ul>
<div id="tabs-1">
<div class="ui-state-default">Item 13</div>
<div class="ui-state-default">Item 23</div>
<div class="ui-state-default">Item 3</div>
<div class="ui-state-default">Item 4</div>
</div>
<div id="tabs-2">
<div class="ui-state-default">Item 1</div>
<div class="ui-state-default">Item 2</div>
<div class="ui-state-default">Item 3</div>
<div class="ui-state-default">Item 4</div>
</div>
</div>
and the JavaScript:
$("#tabs").tabs();
$("#tabs-1, #tabs-2").sortable({
revert: true
});
$("#draggable").draggable({
connectToSortable: '#tabs-1, #tabs-2',
helper: 'clone',
revert: 'invalid'
});
$("ul, li").disableSelection();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来 jQuery 1.4 和/或 jQuery-UI 1.8 有问题。如果你玩这个:
使用 jQuery 1.4.4 和 UI 1.8。 7,您将看到与您所看到的相同的奇怪行为(即切换选项卡后必须与可排序交互,然后才能再次拖放)。但如果你切换到 jQuery 1.7.1 和 UI 1.8.16:
一切似乎都工作正常。所以升级你的方法来解决这个问题。
我还将可拖动对象切换为
以避免生成无效的 HTML,但这不会影响奇怪的行为。我还用
class="draggable"
替换了您的id="draggable"
,再次避免无效的 HTML,但这也不会影响错误行为。Looks there something wrong with jQuery 1.4 and/or jQuery-UI 1.8. If you play with this:
which uses jQuery 1.4.4 and UI 1.8.7, you'll see the same strange behavior that you're seeing (namely that you have to interact with the sortable after switching tabs before you can drag'n'drop again). But if you switch to jQuery 1.7.1 and UI 1.8.16:
everything seems to work fine. So upgrade your way out of the problem.
I also switched the draggable to a
<div>
to avoid producing invalid HTML but that doesn't affect the strange behavior. I also replaced yourid="draggable"
withclass="draggable"
to, again, avoid invalid HTML but this doesn't affect the buggy behavior either.