将div链接到HTML中不同页面上的特定部分 [英] Link a div to a particular section on a different page in HTML

查看:452
本文介绍了将div链接到HTML中不同页面上的特定部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我有一个新的困境.....



我有3个div就像3个盒子,每个div都有一个图像和一些文字写的我我希望当我点击任何地方的任何地方,如果该框然后它将转到另一页,例如如果我在主页然后点击框,那么它将转到网站的service.html页面。



我已经完成了这个

 < div onClick =document.location ='service.html';> 

及其工作。但是当用户点击第一个div 时我想要然后它转到服务.html和那个特定部分,在第二个框中它将转到service.html上的另一个部分,依此类推.......



为了更清楚,我想将div链接到特定页面的特定部分..



我该怎么做?

解决方案

你必须在<$ c $上的元素上添加一个ID c> service.html 您要链接的页面,然后将其包含在您的链接中:

 < div onClick =window.location.href ='service.html#section-1';>转到第1节< / div> 
< div onClick =window.location.href ='service.html#section-2';>转到第2节< / div>

P.S。您使用Javascript而不是常规锚标签的原因是什么?


hey I have a new dilemma.....

I have 3 div like 3 boxes and in each div there is an image and some text written and i want that when i click anywhere in any if the box then it will go to the other page e.g. if i am on home page then on clicking on box then it will go to service.html page in the website.

I have done this by

<div onClick="document.location='service.html';">

and its working.but i want that when user click on first div then it go to service .html and in that particular section and on second box it will go to another section on service.html and so on.......

To be more clear, I want to link a div to a particular section to the particular page..

How can I do this??

解决方案

You'll have to add an ID to the elements on the service.html page you want to link to, and then include them in your links:

<div onClick="window.location.href='service.html#section-1';">Go to Section 1</div>
<div onClick="window.location.href='service.html#section-2';">Go to Section 2</div>

P.S. Any reason you're using Javascript instead of regular anchor tags?

这篇关于将div链接到HTML中不同页面上的特定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆