2012-05-29 43 views
2

我还在学习jQuery,所以我不知道这里发生了什么,但我使用了一个我在css-tricks上找到的过滤脚本,并试图在点击时将内容加载到div中,但是我在url中获得undefinedjQuery .load()help UPDATED

我在不受过滤脚本影响的页面部分做了这个工作,所以我只需要弄清楚什么是冲突。

任何人都可以请帮忙!

所以这是我的jQuery加载在div内容:

$(document).ready(function(){ 
    $('#target').click(function() { 
     event.preventDefault(); 
     $('#target').empty(); 
     $('#target').load('project1.html'); 
    }); 
}); 

这是HTML:

<div id="target"> 
    <div class="sixteen columns clearfix thumbnail photoeditor"> 
     <div class="two-thirds columns alpha"> 
      <img src="images/d1.png" class="scale-with-grid" alt="fieldlazer" /> 
     </div> 
     <div class="one-third columns omega"> 
      <span class="title">Title goes here</span> 
      <span class="details">Description goes here</span> 
     </div> 
    </div> 
</div> 

,这是过滤jQuery脚本:

(function($){ 
    // Shuffle function from: http://james.padolsey.com/javascript/shuffling-the-dom/ 

    $.fn.shuffle = function() { 
     var allElems = this.get(), 
      getRandom = function(max) { 
       return Math.floor(Math.random() * max); 
      }, 
      shuffled = $.map(allElems, function() { 
       var random = getRandom(allElems.length), 
        randEl = $(allElems[random]).clone(true)[0]; 
       allElems.splice(random, 1); 
       return randEl; 
      }); 

     this.each(function(i){ 
      $(this).replaceWith($(shuffled[i])); 
     }); 

     return $(shuffled); 
    }; 
})(jQuery); 

$(function(){ 
    $(".thumbnail") 
     .css("opacity","0.7") 
     .hover(
      function() { $(this).css("opacity","1"); }, 
      function() { $(this).css("opacity","0.7"); } 
     ) 

     $("#allcat").click(function(){ 
      $(".thumbnail").slideDown(); 
      $("#catpicker a").removeClass("current"); 
      $(this).addClass("current"); 
      return false; 
     }); 

     $(".filter").click(function(){ 
      var thisFilter = $(this).attr("id"); 
      $(".thumbnail").slideUp(); 
      $("."+ thisFilter).slideDown(); 
      $("#catpicker a").removeClass("current"); 
      $(this).addClass("current"); 
      return false; 
     }); 

     $(".thumbnail").shuffle(); 
}); 

任何帮助都会非常棒。谢谢!

编辑:另外我想:

$(document).ready(function(){ 

$('#target').click(function(){ 

var link = $(this).attr('rel'); 
event.preventDefault(); 
$('#target').empty(); 
$('#target').load(link); 

}); 
}); 

与HTML:

<div id="target" class="sixteen columns clearfix thumbnail photoeditor" rel="404.html"> 
<div class="two-thirds columns alpha"> 
<img src="images/d1.png" class="scale-with-grid" alt="fieldlazer" /></div> 
<div class="one-third columns omega"> 
<span class="title">Title goes here</span> 
<span class="details">Description goes here</span> 
</div> 
</div> 

依然无果。

编辑:另一个更新

让我有种得到它的工作,但它仅适用于第一个div(PROJECT1),当我清空外部HTML的div和放回的#内容main-它显示的内容很奇怪,并且没有任何功能可用。 有什么建议吗?

这里是新的jQuery:

$(document).ready(function(){ 

$('#portfolio div').click(function(event){ 

var link = $(this).attr('rel'); 
event.preventDefault(); 
$('#main-content').load(link); 

$("#back").live("click", function(event){ 
$('#main-content').empty(); 
$('#main-content').load('index.html #main-content *'); 
}); 
}); 
}); 

和HTML:

<div id="main-content"> 
<ul class="tabs-content"> 
<li class="active" id="portfolio"> 


<ul id="catpicker"> 
<li class="active"><a href="#" id="allcat" class="current">View All</a></li> 
<li><a href="#" id="photoeditor" class="filter">Photo Editor</a></li> 
<li><a href="#" id="producer" class="filter">Producer</a></li></ul> 

<div class="sixteen columns thumbnail photoeditor" rel="project1.html"> 
<div class="two-thirds columns alpha"> 
<img src="images/d1.png" class="scale-with-grid" alt="fieldlazer" /></div> 
<div class="one-third columns omega"> 
<span class="title">Project 1</span> 
<span class="details">Details go here</span> 
</div> 
</div> 

<div class="sixteen columns thumbnail photoeditor" rel="project2.html"> 
<div class="two-thirds columns alpha"> 
<img src="images/d1.png" class="scale-with-grid" alt="fieldlazer" /></div> 
<div class="one-third columns omega"> 
<span class="title">Project 2</span> 
<span class="details">Details go here</span> 
</div> 
</div> 

<div class="sixteen columns thumbnail photoeditor" rel="project3.html"> 
<div class="two-thirds columns alpha"> 
<img src="images/d1.png" class="scale-with-grid" alt="fieldlazer" /></div> 
<div class="one-third columns omega"> 
<span class="title">Project 3</span> 
<span class="details">Details go here</span> 
</div> 
</div> 


</li> 
<li id="words"> 
</li> 
</ul> 
</div><!-- main content --> 

回答

0

我上了阻止默认行的错误,那是因为你忘了事件经过。将事件传递给像这样的.click函数。

$('#target').click(function(event) 

之后,它为我工作。

+0

感谢您的建议。仍然不适合我。 :/ –