jQuery +可排序+实时 [英] jQuery + Sortable + live
问题描述
我正在使用$ .get将列表项动态添加到页面中,然后将其附加到OL元素.到目前为止,这很平常.
I'm adding list items to a page dynamically with $.get, then appending them to the OL element. Pretty usual to this point.
但是当这些新项目加载到页面中时,jQuery并不知道它们,因此我无法对其进行排序.
But jQuery isn't aware of these new items when they get loaded into the page, and I'm not being able to make them sortable.
我使用jQuery Live进行了一些试验,但是没有得到任何帮助...
I made some trials with jQuery Live, but didn't get anywhere whit that...
推荐答案
.sortable()
的refresh
方法似乎无法识别未通过.sortable()
函数添加的li
.
The refresh
method of .sortable()
does not seem to recognize li
's which are NOT added via the .sortable()
functions.
尝试将您的.sortable()
初始化代码添加到一个函数中,该函数可在准备好文档的情况下调用,并在您的代码中动态添加li
.
Try adding your .sortable()
initialisation code into a function which you call on document ready AND in you code where you dynamically add li
's.
代替:
jQuery(document).ready(function() {
jQuery("#mySortableOL").sortable({
...
});
}
...
jQuery("#mySortableOL").append(...);
jQuery("#mySortableOL").sortable("refresh");
尝试类似的东西:
jQuery(document).ready(function() {
jQuery("#mySortableOL").doSort();
}
...
jQuery("#mySortableOL").append(...);
doSort();
...
function doSort(){
jQuery("#mySortableOL").sortable({
...
});
}
这篇关于jQuery +可排序+实时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!