0

I'm using jquery's sortable to resort a list. The items are numbered so I'd like to be able to indicate the new numbers as well after the resort. Originally, I reloaded the page after doing the sort. However, I've just "discovered" ajax and find that it's a potentially much cleaner solution. My code almost works except for one issue. When the page is first loaded before the sort, a bunch of span tags are hidden; after I do my ajax call, however, they become unhidden, and I'd like them to remain hidden. I've tried:

 $.ajax({
                url: "/main_scripts/sort_chapters_and_sections.php",
                type: "POST",
                data: newOrder,
                success: function(thing_reordered){                                            $(".inline_link_list").html(thing_reordered);

$("span").each(function(){
    if ($(this).attr('class').match(/\bspan_hidden/)){
         $(this).hide();
    }
});
}
});

However, after the call, my span_hidden tags become unhidden. My guess is that the ajax call isn't completed yet so that my "span_hidden" tags are not yet in the browser and subsequently, there's nothing yet to hide. If I could understand how to ensure that the ajax call is completed finished, I can test this theory out. Any help would be appreciated.

4

1 回答 1

0

if 语句似乎是错误的。此外,您不需要使用 each() 进行如此简单的搜索。

试试看嘛:

$('.span_hidden').hide();
于 2013-01-10T15:55:49.647 回答