2011-05-09 42 views
0

我想使用超鏈接調用特定的div。這裏是我的代碼:如何使用html超鏈接調用特定的div

<div id="mainNavPane"> 
    <ul id="sideSubNav"> 

     <li><a href="#" class="prim">Individuals</a></li> 
     <li><a href="#" class="view">Individuals1</a></li> 
    </ul> 
</div> 

<div id="mainScrollPane"> 


<!-- 1-5 --> 
    <div id="homeScreen" class="screen"> 
    <div class="arrowLeft" style="width:50px;"><a class="prev"><img src="../images/btn-ArrowPrev.gif"/></a></div> 
    <img src="images/bg-HomeScreen.jpg" height=50px width=50px /> 
    <div class="arrowRight" style="width:50px;"><a class="next"><img src="../images/btn-ArrowNext.gif" /></a></div> 
    </div> 

    <!-- 5-10 --> 
    <div id="IndividualsScreen" class="screen"> 
    <h2>Individuals using Breaking Free Online</h2> 
    <div class="arrowLeft" style="width:50px;"><a class="prev"><img src="../images/btn-ArrowPrev.gif" /></a></div> 
    <div class="screenBody" style="width:460px;"> 
     <ul> 
      <li>If you are struggling to control your drinking or use of drugs, Breaking Free Online 
       offers you treatment that is immediate, confidential and effective – even if your 
       dependence is severe and has been for a long time </li> 
      <li>You can take advantage of the treatment at home or anywhere with an internet connection, 
       and at the times that are most convenient for you, because it is available online 
       24 hours a day </li> 
      </ul> 
     </div> 
     <div class="arrowRight" style="width:50px;"><a class="next"><img src="../images/btnArrowNext.gif" /></a></div> 
    </div> 
    </div> 

我想顯示div id = individualscreen當點擊超鏈接<a href="#" class="prim">Individuals</a>同樣,當<a href="#" class="view">Individuals1</a>應顯示div id=homescreen

+0

你想擁有'div'隱藏的開始,然後當它顯示你點擊鏈接,或者你只是想讓頁面跳到'div'當你點擊鏈接? – Town 2011-05-09 10:45:24

回答

3

只需使用#後跟元素ID:href="#individualscreen"

+0

我試過了,但它不起作用 – 2011-05-09 10:39:08

+0

@Muhammad Awais:應該可以工作...... [這是一個演示](http://jsfiddle.net/Town/3Yqwt/)。 – Town 2011-05-09 10:42:21

+0

你的例子工作,但我不知道同樣的事情不在我的情況下工作可能是JavaScript或CSS是衝突,因爲我使用可滾動屏幕 – 2011-05-09 10:48:14

1

如果要導航到div,可以按照David Dorward的示例進行操作。

如果你想隱藏/顯示div鏈接被點擊的時候,你可以做這樣的事情:

$(function() { 
    $('#prim').click(function(e) { 
    e.preventDefault(); 
    $('#individualscreen').toggle(); 
    }); 
});