Html 如何在没有 href 属性的链接中显示小手?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4678361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 06:08:11  来源:igfitidea点击:

How to show the little hand in a link that doesn't have the href attribute?

htmlajaxhyperlink

提问by ziiweb

i have this link <a>jander</a>.

我有这个链接<a>jander</a>

When I put the mouse cursor over it, the selection cursor is shown instead of the little hand.

当我将鼠标光标放在它上面时,会显示选择光标而不是小手。

Is there any way to show the little hand?

有什么办法可以秀出小手吗?

Note: I don't want to use href='#' because it is that case when I click on the link (it's a link that executes ajax function), it goes to the top of the page.

注意:我不想使用 href='#' ,因为当我点击链接(它是一个执行 ajax 函数的链接)时,它会转到页面顶部。

回答by Paddy

Style the cursor as so:

为光标设置样式:

<a style="cursor:pointer;">jander</a>

回答by harpo

Use

cursor: pointer;

in the element's style or class. Note that this will work on any element — not just a.

在元素的样式或类中。请注意,这适用于任何元素——不仅仅是a.

By the way, you can always return falsein your handler to avoid the problem you have with href="#".

顺便说一句,你总是可以return false在你的处理程序中避免你遇到的问题href="#"

回答by Thomas Hunter II

You can also do:

你也可以这样做:

<a href="javascript:;">jander</a>

This prevents the scroll to the top of the page and keeps your links having an href attribute (ideal in some situations where CSS is locked or if you have a limiting CMS).

这可以防止滚动到页面顶部并保持您的链接具有 href 属性(在某些情况下 CSS 被锁定或如果您的 CMS 受限)是理想的。

回答by Anthony Grist

Add style="cursor:pointer;"to your atag.

添加style="cursor:pointer;"到您的a标签。

回答by Nazrul Muhaimin

if you want to set for all <a>attribute set this in your css file.

如果要为所有<a>属性设置,请在 css 文件中设置此项。

a {
  cursor:pointer;
}

回答by Simon Müller

When you use links for JavaScript you can also use <a href="javascript:false">jander</a>or <a href="#" onClick="ajaxFunction(); return false;">the return false will 'deactivate' the href attribute

当您使用 JavaScript 链接时,您也可以使用, <a href="javascript:false">jander</a>否则 <a href="#" onClick="ajaxFunction(); return false;">返回 false 将“停用”href 属性

回答by Saket Mehta

When using Bootstrap, you can do the following:

使用Bootstrap 时,您可以执行以下操作:

<a role="button">jander</a>

回答by Joe Velez

avoid inline styles! use a class

避免内联样式!使用一个类

<style>
.no-href-but-gimme-pointer{cursor:pointer;}
</style>
<a class='no-href-but-gimme-pointer'>hover me for pointer, but don't click me -- i won't do anything!</a>