通过单击事件导航 ID



我在网站工作,我有2个页面索引.html和产品.html,在产品中.html我有 2 个具有不同 ID 的div 元素,现在当我单击索引中的锚标签时.html它导航到产品.html但它应该导航到包含产品中不同内容的特定 ID.html需要帮助

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

在产品.html页面我得到了 2div

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

当我单击锚标记时,我应该导航到特定 ID,就像单击基础架构锚标记一样,它应该直接导航到产品.html基础架构div

只需将该ID添加到您的href中即可。喜欢产品.html#分裂

索引.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 和产品.html文件并粘贴上面的代码。它按预期工作。

最新更新