简体   繁体   English

我可以禁用 HTML 中的地址链接吗?

[英]Can I disable an address link in HTML?

I have the following:我有以下内容:

<a href="/Product/Overview">Overview</a>
<a href="/Product/Review">Review</a>

When I am on the overview page I want to make it so that clicking the overview address link does nothing.当我在概述页面上时,我想这样做,以便单击概述地址链接什么都不做。 Something like disable for a button.诸如禁用按钮之类的东西。 Is this possible for an address link?这可能用于地址链接吗?

This should do it:这应该这样做:

<a href="/Product/Overview" onclick="return false;">Overview</a>

Of interest may also be nofollow :感兴趣的也可能是nofollow

<a href="/Product/Overview" onclick="return false;" rel="nofollow">Overview</a>

The easiest way to disable a link is probably to remove the href value.禁用链接的最简单方法可能是删除 href 值。

If you are rendering this from MVC, simply don't include the <a> tag.如果您从 MVC 呈现它,只需不包含<a>标记。

It's a little unclear what is best for what you're trying to do.有点不清楚什么最适合您尝试做的事情。

Add 'return false' to prevent linking:添加'return false'以防止链接:

<a href="/Product/Overview" onclick="return false">Overview</a>

Just use a # sign in the href like so: <a href="#">Overview</a>只需在href中使用#符号,如下所示: <a href="#">Overview</a>

You could do this with a layer of javascript on top of each page: your JS script would run and check all the links on the page -- if the link is the same as the page you are on then simply "hijack" the anchor by adding an onclick event which does nothing and doesn't bubble up the event.您可以在每个页面顶部使用一层 javascript 来执行此操作:您的 JS 脚本将运行并检查页面上的所有链接——如果链接与您所在的页面相同,则只需“劫持”锚点添加一个onclick事件,它什么都不做,也不会冒泡事件。 This was you still pump out from your server side all the links -- and the script would be the same for all the pages, thus allowing it to be cached by the browser and only loaded once (assuming you place it in an external .js file).这是您仍然从服务器端抽出所有链接 - 所有页面的脚本都是相同的,因此允许它被浏览器缓存并且只加载一次(假设您将它放在外部.js文件)。

You can try <a class="inactive" href="#">Overview</a> and give it some CSS to show it's a different type of link.您可以尝试<a class="inactive" href="#">Overview</a>并给它一些 CSS 以表明它是一种不同类型的链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM