2012-04-22 78 views
0

鏈接我有2個HTML文件:執行從外部HTML文件

  • 的index.html
  • portfolio.html

在portfolio.html我有4個類別我的工作:網絡, 3d,代碼和視頻。另外我還加入了一個過濾器腳本,它只顯示所選類別的工作,並且它正在工作。

在index.html中,我需要鏈接指向我的投資組合的每個類別,但我不知道如何執行此操作。

這裏是代碼:

的Index.html:

... 
<a href="portfolio.html#web"><img src="img/web.png"></a> 
<a href="portfolio.html#triD"><img src="img/triD.png"></a> 
<a href="portfolio.html#codes"><img src="img/codes.png"></a> 
<a href="portfolio.html#video"><img src="img/video.png"></a> 
... 

Portfolio.html:

... 
<!-- filter goes here: --> 
<p id="picker"> 
    <a href="#" id="all" class="current" name="all">All</a> | 
    <a href="#" id="web" class="filter" name="web">Web</a> | 
    <a href="#" id="triD" class="filter" name="triD">3D</a> | 
    <a href="#" id="codes" class="filter" name="codes">Codes</a> | 
    <a href="#" id="video" class="filter" name="video">Video</a> 
</p> 

<!-- my work goes here: --> 
<div class="my-work codes">...</div> 
<div class="my-work web">...</div> 
<div class="my-work triD">...</div> 
<div class="my-work codes">...</div> 
... 

Filter.js:

$(function() 
{ 
    $("#all").click(function(){ 
     $(".my-work").slideDown(); 
     $("#catpicker a").removeClass("current"); 
     $(this).addClass("current"); 
     return false; 
    }); 

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

}); 
+0

這是一個JavaScript的問題,而不是HTML的問題。如何做你提出的問題,或者甚至可能,完全取決於你使用的過濾器腳本的工作方式。請發佈腳本。 – Andrew 2012-04-22 19:34:02

+0

我已經添加了filter.js腳本(它是用jQuery編寫的)。目前它只包含在portfolio.html中 – 2012-04-23 08:24:21

回答

0

其實我已經找到m的正確答案問題。 在portfolio.html,在標題中的所有腳本之後,應該增加以下腳本:

$(document).ready(function() 
{ 
    var type = window.location.hash; 
    //window.location.hash = window.location.hash.replace(type,''); //should be added if you want to remove: ...#class in address bar 
    $(type).trigger('click'); 
});