我有以下静态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"});
})