当使用AJAX html填充时,Jquery Custom Content Scroller会删除Div内容

时间:2013-10-13 13:02:20

标签: jquery ajax scroller

我正在使用来自http://manos.malihu.gr/的Jquery自定义内容滚动条,它似乎非常受欢迎。我最初尝试使用它,然后切换到Nicescroller,它最初工作正常,但后来我用它的功能撞墙,现在回到这里......

我正在做的事情并不复杂。数据来自AJAX并被送入DIV,然后在AJAX成功时将滚动条应用于DIV。 DIV实际上用于显示表单错误消息,其周围的主要HTML是表单字段。我认为这不相关,但我想提供所有相关信息。

以下是AJAX调用的“成功”部分:

 success: function (data) {     
    $('#error_msg_div').html(data); 
    if (submit_status != "OK") //submit_status is a JS variable in data not set to OK  
    { //alert(..) here. At alert pause, error_msg_div shows AJAXed response data.
      //AJAXed response data has absolutely no reference to the DIV or the scroller 
      $("#error_msg_div").mCustomScrollbar({
        theme:"dark",
        scrollButtons:{
            enable:true
            },
        updateOnContentResize:true
      });  
    };
 },

来自AJAX响应的示例数据(从firebug复制)如下所示:

  <div class='err_no' style='left:0px;top:5px;'>1:</div><div style='left:22px;top:5px;' class='err_msg'>First name must have 2 to 20 alphabets only.</div>
  <div class='err_no' style='left:0px;top:17px;'>2:</div><div style='left:22px;top:17px;' class='err_msg'>Middle initial can only be a single uppercase alphabet.</div>

那么,问题是什么? AJAX响应没问题。在警报时,可以看到DIV填充了数据。就在那之后,$(“#error_msg_div”)。mCustomScrollbar({...空白div。在firebug中没有显示JS错误消息。

我尝试使用静态数据的滚动条,它工作正常。唯一的主要区别是在我的普通静态HTML中使用,这是在静态测试HTML文件中,滚动条被调用为:

 (function($){
     $(window).load(function(){
        $("#xxxxxxxxscroll_div").mCustomScrollbar({
          theme:"dark",
          scrollButtons:{
            enable:true
          },
        updateOnContentResize:true
      });
    });
  })(jQuery);

我花了很多时间在这上面。我喜欢卷轴不要再放弃它。一旦我想出这个,我认为功能集的其余部分将易于使用。一个跟进问题,很可能是不相关的,当我“破坏”滚动条时,Div上的mCustomScrollbar方法仍然显示。这只是一个侧面问题......我不是JS大师,但当滚动文档声明该元素恢复到其预调用状态时,我原本预计这种方法会消失。正确?

谢谢!我对这个论坛比较陌生。如果格式或细节措辞不合适,请原谅。

0 个答案:

没有答案