jQuery +可排序+实时 [英] jQuery + Sortable + live

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

问题描述

我正在使用$ .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屋!

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