Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AJAX加载内容后滚动条不工作_Javascript_Jquery_Html_Ajax_Jquery Load - Fatal编程技术网

Javascript AJAX加载内容后滚动条不工作

Javascript AJAX加载内容后滚动条不工作,javascript,jquery,html,ajax,jquery-load,Javascript,Jquery,Html,Ajax,Jquery Load,我正在尝试使用Ajax加载div。div确实加载,但div所包含的滚动条在加载后不起作用 我有一个Main.html,在这里我将其他html的内容加载到 <div id="content1" > </div> home.html的内容如下所示: $("#content1").load("home.html"); $("#home, #product, #submit2").click(function(){ if(this.id == "h

我正在尝试使用Ajax加载div。div确实加载,但div所包含的滚动条在加载后不起作用

我有一个Main.html,在这里我将其他html的内容加载到

<div id="content1" > </div>
home.html的内容如下所示:

$("#content1").load("home.html");

     $("#home, #product, #submit2").click(function(){
         if(this.id == "home"){
             $("#content1").load("home.html");
         }

         if(this.id == "product"){
             $("#content1").load("product.html");
         }
<script type="text/javascript">
        (function($){
            $(window).load(function(){

                $.mCustomScrollbar.defaults.scrollButtons.enable=true; //enable scrolling buttons by default
                $.mCustomScrollbar.defaults.axis="yx"; //enable 2 axis scrollbars by default

                $("#content-m").mCustomScrollbar({theme:"minimal"});

            });
        })(jQuery);
    </script> 


<div id="content-m" class="content">
                //bla bla...
    </div>

(函数($){
$(窗口)。加载(函数(){
$.mCustomScrollbar.defaults.scrollButtons.enable=true;//默认情况下启用滚动按钮
$.mCustomScrollbar.defaults.axis=“yx”//默认情况下启用2轴滚动条
$(“#content-m”).mCustomScrollbar({theme:“minimal”});
});
})(jQuery);
//布拉布拉。。。
当未加载AJAX时,滚动条不起作用。所以我相信这不是问题所在

有人能帮我让我的滚动条与Ajax一起工作吗

找到了解决方案

您需要像这样在load函数中调用滚动条,而不是像我那样在external home.html中调用滚动条

$("#content1").load("home.html", function(){
             $("#content-m").mCustomScrollbar({theme:"minimal"});
         });

     $("#home, #product, #submit2").click(function(){
         if(this.id == "home"){
             $("#content1").load("home.html", function(){
                 $("#content-m").mCustomScrollbar({theme:"minimal"});

             });
         }
现在将加载内容,加载后滚动条将工作。

找到了解决方案

您需要像这样在load函数中调用滚动条,而不是像我那样在external home.html中调用滚动条

$("#content1").load("home.html", function(){
             $("#content-m").mCustomScrollbar({theme:"minimal"});
         });

     $("#home, #product, #submit2").click(function(){
         if(this.id == "home"){
             $("#content1").load("home.html", function(){
                 $("#content-m").mCustomScrollbar({theme:"minimal"});

             });
         }

现在将加载内容,然后滚动条将在加载后工作。

如果有一个代码段就太好了。这里有一个人据说已经解决了这个问题。虽然我真的不知道他在干什么。有一个片段会很好,这里有一个人应该已经解决了这个问题。虽然我真的不知道他在干什么。