在ajax调用我的文档准备好的脚本后不起作用

时间:2015-08-04 12:20:48

标签: javascript jquery

我想在AJAX之后隐藏一个div,但它不起作用。我的脚本在AJAX调用之前工作,但之后第一个脚本不起作用。如何隐藏我的div

$(function () {
    $("div.product-spec-filter div.filter-content").hide(); // this line not work after ajax call       

}); 

1 个答案:

答案 0 :(得分:0)

如果像这样实施,它应该有效:

    //bogus ajax call just to give an example of the done functionality
    $.ajax({

      method: "POST",

      url: "some.php",

      data: { name: "John", location: "Boston" }

    })

      .done(function( msg ) {

        //this will fire when the ajax request returns success.
        hideDiv();

      });



    function hideDiv() {
        $("div.product-spec-filter div.filter-content").hide(); // this line not work after ajax call
        //$("div.product-spec-filter div.filter-title").click(function () {
        $("div.product-spec-filter div.filter-title").on("click", function () {
            $("div.category-listbox-title").next("div.listbox").slideToggle("slow");
            $(this).next("div.filter-content").slideToggle("slow");
        });

        //$("div.block-category-navigation div.category-listbox-title").click(function () {
        $("div.block-category-navigation div.category-listbox-title").on("click", function () {
            $("div.product-spec-filter").find("div.filter-content").slideToggle("slow");
            $(this).next("div.listbox").slideToggle("slow");
        });

    }