链接到本地​​托管网站中的某个位置 [英] link to a place in a locally-hosted website

查看:36
本文介绍了链接到本地​​托管网站中的某个位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的本地托管网站链接到特定 ID(网站内部),如下所示:

I'm trying to have my locally-hosted website link to a specific id (inside the website) as follows:

<button onclick="location.href='http://127.0.0.1:5500/#projects'" 
onmouseover="onbutton(this)" onmouseout="offbutton(this)"
type="button">Projects</button>

但是,它不起作用(单击时我浏览器中的 url 更改为 127.0.0.1:5500/#projects,但超链接不会更改我正在查看的页面的哪一部分.我怀疑这是因为ip 不是真正的 url.当我的网站在本地托管时,有什么方法可以创建指向 id projects 的超链接?

However, it is not working (the url in my browser changes to 127.0.0.1:5500/#projects when clicked, but the hyperlink does not change which part of the page I'm looking at. I suspect it's because the ip is not a real url. Is there any way I can create a hyperlink to the id projects when my website is being locally hosted?

推荐答案

您可以使用 标签内的按钮.

You could the button inside an <a> tag.

<a href="http://127.0.0.1:5500/#projects"><button
type="button">Projects</button></a>

这篇关于链接到本地​​托管网站中的某个位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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