jQuery的生活和排序 [英] jQuery live and sortable

查看:107
本文介绍了jQuery的生活和排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下静态html​​:

I have the following static html:

<ul id="mylist">
    <li id="li_10"><a href="10">Item 10</a></li>
    <li id="li_20"><a href="20">Item 20</a></li>
    <li id="li_30"><a href="30">Item 30</a></li>
    <li id="li_40"><a href="40">Item 40</a></li>
    <li id="li_50"><a href="50">Item 50</a></li>
</ul>

我有以下jQuery的:

I have the following jQuery:

<script>
    $( document ).ready( function() { 
        $("#mylist").sortable(
            {axis:"y"}
        );
    });
</script>

这完美的作品,但停下,我使用jQuery / AJAX来生成上面的HTML尽快工作。所以我假设我需要使用jQuery的活的功能做了排序部分。有人可以帮助我实现这个?

This works perfectly, but stops working as soon as I use jQuery/AJAX to generate the above HTML. So I am assuming I need to use the "live" function in jQuery to do the sortable section. Can someone help me implement this?

推荐答案

.live( ) 是基于事件的,所以你不能用它来做这样的插件。你的什么可以的容易做的就是调用code,当你的AJAX调用完成,例如:

.live() is event based, so you can't use it for plugins like this. What you can easily do is call that code when your AJAX call finishes, for example:

$.ajax({
 //options...
  success: function(data) {
    //create UL
    $("#mylist").sortable({axis:"y"});
  }
});

这同样适用于短期形式 $的。阿贾克斯() ,例如:

The same goes for short forms of $.ajax(), for example:

$("#mylist").load("pageThatGivesTheLIElementGoodness.htm", function() {
  $(this).sortable({axis:"y"});
})

这篇关于jQuery的生活和排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆