2012-01-22 25 views
1

我正在构建几个加载了ajax的级别,而当前级别菜单位于右侧并且需要将其放在内容区域中。我不确定如何在ajax加载的内容中加载一个点击事件,在它自己的内容div中加载另一个级别。德代码我工作是在这里:如何在ajax加载的内容中加载带有链接的另一个页面

var $level = $('#navigation a'),// Links on the right 
    last = null;// Last Level 

$level.click(function(){ 
    if(last != this){ // let's avoid needless requests 
     var url = 'html/' + this.hash.slice(1) + '.html'; 
     $('#content').html('<p class="loading">Loading...</p>').load(url, function(){ 
      this.scrollLeft = 0;//scroll back to the left 
     }); 
    } 
    last = this; 
    this.blur(); // Remove the awful outline 
    return false; 
}); 

$level.eq(0).click(); // Load the first Level 

的最终目标是让用户能够挖掘的内容区域内的图像(即的Ajax加载)到该级别内浏览,或加载另一个级别(.html页面)。我试图避免是必须在脚本中声明每个级别的每个实例一样会有超过5

我的测试环境是在这里:http://www.beingproperties.com/test/jscroll-ajax/

任何帮助,将不胜感激。谢谢! -Chris

+0

为了使事件(例如$('#mydiv')。live('click',function(e){your codes}); –

+0

那么上面的代码如何被重写。我已阅读这里的信息(http://beski.wordpress.com/2010/11/01/jquery-ajax-link-inside-ajax-loaded-content-problem/),但我不清楚如何编写我不必定义每个页面加载。 – Centinel3

回答

0

您应该直接将您的代码从绑定更改为click事件以使用实时绑定。

取而代之的是:

$level.click(function() { 

你应该使用这样的:

$level.live('click', function() { 

如果您正在使用jQuery 1.7+正确的语法是:

$('#navigation').on('click', 'a', function() { 
+0

绝对完美。 –

相关问题