【问题标题】:jQuery sortable: How to automatic order <li> in a sortable by <li> classes?jQuery sortable:如何在 <li> 类中自动排序 <li>?
【发布时间】:2012-06-01 12:14:28
【问题描述】:

我在#a sortable div 中回显了一些 &lt;li class='A'&gt; 或 class='B' 或 class='C'。 然后用户将它们移动到#b 可排序的 div 中。我需要在#b &lt;li&gt; 自动他们的班级desc字母顺序对自己进行排序(C->B->A)并且,第二次,按&lt;li&gt;内容 (&lt;li class='X'&gt;content&lt;/li&gt;) 的字母顺序排列。

我如何在&lt;head&gt; 中编写脚本?

【问题讨论】:

    标签: jquery-ui-sortable


    【解决方案1】:

    jQuery UI 有很好的可排序的东西。这是demos

    尝试使用update event 强制执行您的订购。

    $( ".selector" ).sortable({
     update: function(event, ui) {
       $("find the LIs you want").sort(
         function(a, b){
           var aName = a.name.toLowerCase();
           var bName = b.name.toLowerCase(); 
           return ((aName < bName) ? -1 : ((aName > bName) ? 1 : 0));
        });
     }
    });
    

    排序代码来自this answer

    【讨论】:

    • 我用 sortable 做到了!我需要“自动”部分!
    猜你喜欢
    • 2018-11-17
    • 2012-06-07
    • 2020-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-23
    • 1970-01-01
    相关资源
    最近更新 更多