2016-05-30 6 views
-1

私は2ページのindex.htmlとproduct.htmlを持っています。product.html 異なるIDを持つdiv要素が2つあります。インデックスのアンカータグをクリックするとナビゲートするの.htmlはproduct.htmlするが、それはproduct.htmlに異なるコンテンツを保持することは、私が得たproduct.htmlページでクリックイベントによるIDによるナビゲーション

In index.html page i have anchor tag 
<a href=products.html>Building</a> 
<a href=products.html>Infrastructure</a> 

を助ける必要が特定のIDに移動しなければならない2 divの

<div id=#Building> 
<div class="container"> 
</div> 
<div> 

<div id=#Infrastructure> 
<div class="container"> 
</div> 
<div> 

とき、私アンカータグをクリックしてください。Infrastrucをクリックすると、特定のIDに移動する必要があります。アンカータグを直接product.htmlインフラストラクチャ部門に移動する必要があります

+0

これまでに何を試みましたか? SO –

+0

に関する助けを得るためにいくつかのコードをダンプしてください。 – brk

+0

@kitty あなたはあなたが望むdiv idを挙げることもできます。 => 'href =" product.html#myDiv "' –

答えて

0

あなたのhrefにそのIDを追加するだけです。 product.html#のdivIdは同様

index.htmlを

<html> 
<body> 
<a href='products.html#Building'>Building</a> 
<a href='products.html#Infrastructure'>Infrastructure</a> 
</body> 
</html> 

products.html 

<div id='Building'> 
<div class="container"> 
building<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> 
</div> 
<div> 

<div id='Infrastructure'> 
<div class="container"> 
Infrastructure 
</div> 
<div> 

inedx.htmlとproducts.htmlファイルを作成し、コードの上に貼り付けます。 期待通りに機能します。

+0

そのページにリダイレクトするのではなく、特定のIDにリダイレクトしますdiv –

+0

あなたはidsが間違った方法で、なぜそれが働かないかを教えました。 –

+0

私はindex.htmlとproduct.htmlの両方が別のページ –

関連する問題