2012-08-11 61 views
0

我的页面我动态更新页面,由数据库填充。你选择州和城市,他告诉你在城里可以买到的商店。有些城市有一个相当广泛的商店列表,所以我需要一个滚动条。我正在使用mCustomScrollbar。从另一个页面执行jquery函数?

对于它的工作,所以我把这个脚本:

<script> 
    (function($){ 
     $(window).load(function(){ 
      $("#exibe_lojas").mCustomScrollbar({ 
       scrollButtons:{ 
        enable:true 
       }, 
       autoDraggerLength: false 
      }); 
     }); 
    })(jQuery); 
</script> 

但是,因为我还没有内容,我加载我的数据之后调用它,这谁做的是另一种JavaScript文件,它在数据库中进行查询,并将结果显示在一个div中。鉴于结果我这样做:

function stateChanged() 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") 
    { 
     document.getElementById("exibe_cidade").innerHTML=xmlHttp.responseText 
    } 
} 

我认为这是在这里,我把我的滚动条的功能,但因为它是在另一个文件;我不知道如何称呼它。你能帮我吗?

回答

0

最明显的方法是把代码到stateChanged方法,但是如果文件内容不能编辑,你可以听ID为“exibe_cidade”的元素含量变化:

$('#exibe_cidade').bind('contentchanged', function() { 
    $("#exibe_lojas").mCustomScrollbar({ 
     // your magic here 
    }); 
}); 
+0

OPS。我已经尝试过,并没有奏效 – Preston 2012-08-11 01:15:04

0

试试这个:

function stateChanged() 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") 
    { 
     document.getElementById("exibe_cidade").innerHTML=xmlHttp.responseText; 

     $("#exibe_lojas").mCustomScrollbar({ 
      scrollButtons:{ 
       enable:true 
      }, 
      autoDraggerLength: false 
     }); 
    } 
} 
+0

,你肯定mCustomScrollbar实际工作? – Preston 2012-08-11 00:40:53

+0

这应该工作这不工作... – redmoon7777 2012-08-11 15:56:32

相关问题