2010-05-21 134 views
0

我可以用戶jquery在另一個頁面上顯示/隱藏特定 div嗎?jQuery顯示/隱藏

即我有Content.aspx,顯示我們提供的不同計劃的內容。

在detail.asp我有一個更詳細的頁面,有獨特的divs。

<div id="detail-a"> 
    detailed content here for product A. 
</div> 

<div id="detail-b"> 
    detailed content here for product B. 
</div> 

我不想顯示隱藏框,滾動顯示的頁面內容詳細休息... 如果這都有道理...

回答

1

如果我正確閱讀此內容,您希望鏈接到一頁上,以便將用戶發送到第二頁,並在第二頁上顯示或隱藏特定的div,具體取決於用戶在第一頁上單擊的鏈接。

Contents.aspx

<a href="details.asp#detail-a">See Detail A</a> 
<a href="details.asp#detail-b">See Detail B</a> 

details.asp

<div id="detail-a"> 
    Data on Detail A 
</div> 
<div id="detail-b"> 
    Data on Detail B 
</div> 
<script type="text/javascript"> 
$(document).ready(function(){ 
    /* If there is a Hash and the Hash is an ID on this page */ 
    if(document.location.hash && $(document.location.hash)) { 
    /* Hide all the Detail DIVs */ 
    $('div[id^="detail-"]').not(document.location.hash).hide(); 
    /* Show the Specified Detail DIV */ 
    $(document.location.hash).show(); 
    } 
}); 
</script> 
0

您可以設置DIV顯示:無。 Like:

$(「#mydiv」)。css(「display」,「none」);

編輯: 我沒有真正測試過這一點,但不能你開始每個div作爲顯示:無和您的鏈接到新窗口添加一個哈希像:mypage.htm /#detail1。

然後在文檔準備好的那個頁面上獲取location.href並設置該元素的顯示,如上所述。

這不是一個答案,只是一個未經測試的建議。這可能是一個更優雅的解決方案。

+0

清楚我一直在尋找的是內容頁面上,你可以點擊一個鏈接,它會打開一個只顯示detail.asp頁面上的Detail-A div的大小窗口......因此基本上顯示了來自單獨頁面的特定div。 – 2010-05-21 16:49:18

+0

而不是手動設置CSS屬性,最好使用jQuery的內置Show(http://docs.jquery.com/Show),Hide(http://docs.jquery.com/Hide)和Toggle(http: //api.jquery.com/toggle/)函數。 – 2010-05-22 09:05:36