It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center
                            
                        
                    
                
                                7年前关闭。
            
                    
我有以下代码:

<ul id="sortable1" class="connectedSortable">
<li class="ui-state-default">Song Description 1</li>
<li class="ui-state-default">Song Description 2</li>
</ul>

<ul id="sortable2" class="connectedSortable">
<li class="ui-state-default">Song Description 3</li>
<li class="ui-state-default">Song Description 4</li>
</ul>


我需要做的是将其拖放(例如,歌曲描述1从#sortable1#sortable2中的某个位置)以提醒我(例如,来自#sortable1的歌曲1被放置在#sortable2中)

那可能吗?我应该在“ li”上添加ID吗?

帮助非常感谢。

最佳答案

无需将id添加到可排序项目中,jQueryUI提供了回调函数(请参见http://jqueryui.com/demos/sortable/上的事件),您可以在发生某些事件时将其挂钩。在下面的示例中,我使用了接收回调,该回调传递了事件和ui对象参数,其中包含构造消息所需的所有内容。

的JavaScript

​$('#sortable1, #sortable2').sortable({
    connectWith: '.connectedSortable',
    receive: function(event, ui) {
        console.log(ui.item.html() + ' from #' + ui.sender.context.id + ' was dropped in #' + this.id);
    }
});​


也做了一个demo on jsFIddle

关于javascript - 在jQuery UI中获取ul和li值,拖放后可排序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12215167/

10-10 21:42