将光标更改为手指指针

发布于 2024-12-26 06:52:29 字数 347 浏览 0 评论 0原文

我有这个 a ,但我不知道我需要插入“onmouseover”,以便光标会像常规链接一样变为手指指针:

<a class="menu_links" onclick="displayData(11,1,0,'A')" onmouseover=""> A </a>

我在需要放置的地方读到:

onmouseover="cursor: hand (a pointing hand)"

但这对我不起作用。

另外,我不确定这是否被视为 JavaScript、CSS,或者只是纯 HTML。

I have this a and I don't know that I need to insert into the "onmouseover" so that the cursor will change to finger pointer like a regular link:

<a class="menu_links" onclick="displayData(11,1,0,'A')" onmouseover=""> A </a>

I read somewhere that I need to put:

onmouseover="cursor: hand (a pointing hand)"

But it's not working for me.

Plus I'm not sure if this is considered JavaScript, CSS, or just plain HTML.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

岁月流歌 2025-01-02 06:52:29
<a class="menu_links" onclick="displayData(11,1,0,'A')" onmouseover="" style="cursor: pointer;"> A </a>

这是CSS。

或者在样式表中:

a.menu_links { cursor: pointer; }
<a class="menu_links" onclick="displayData(11,1,0,'A')" onmouseover="" style="cursor: pointer;"> A </a>

It's css.

Or in a style sheet:

a.menu_links { cursor: pointer; }
听风吹 2025-01-02 06:52:29

您可以在 CSS 中执行此操作:

a.menu_links {
    cursor: pointer;
}

这实际上是链接的默认行为。您必须以某种方式在 CSS 中的其他位置覆盖它,或者其中没有 href 属性(您的示例中缺少该属性)。

You can do this in CSS:

a.menu_links {
    cursor: pointer;
}

This is actually the default behavior for links. You must have either somehow overridden it elsewhere in your CSS, or there's no href attribute in there (it's missing from your example).

一刻暧昧 2025-01-02 06:52:29

如果页面上只有一个链接,我喜欢使用这个:

onMouseOver="this.style.cursor='pointer'"

I like using this one if I only have one link on the page:

onMouseOver="this.style.cursor='pointer'"
森林很绿却致人迷途 2025-01-02 06:52:29

在CSS中写

a.menu_links:hover{ cursor:pointer}

in css write

a.menu_links:hover{ cursor:pointer}
潇烟暮雨 2025-01-02 06:52:29

我认为上面的“最佳答案”尽管在编程上是准确的,但实际上并没有回答所提出的问题。问题询问如何更改鼠标悬停事件中的指针。我看到一些帖子,内容是关于如何在某个地方可能会出现错误而没有回答问题。在接受的答案中,鼠标悬停事件为空白 (onmouseover=""),并且包含样式选项。令人费解的是为什么要这样做。

询问者的链接可能没有问题。考虑以下 html:

<a id=test_link onclick="alert('kinda neat);">Click ME!</a>

当用户鼠标悬停在该链接上时,指针不会变为手形...相反,指针的行为就像悬停在普通文本上一样。人们可能不希望这样......因此,需要告诉鼠标指针进行更改。

正在寻找的答案是这样的(这是由另一个人发布的):

<a id=test_link onclick="alert('Nice!');"
       onmouseover="this.style.cursor='pointer';">Click ME!</a>

然而,如果你有很多这样的东西,或者到处使用这种东西并决定做出某种改变,这就是一场噩梦或遇到错误。最好为其创建一个 CSS 类:

a.lendhand {
  cursor: pointer;
}

那么:

<a class=lendhand onclick="alert('hand is lent!');">Click ME!</a>

还有许多其他方法可以说比这种方法更好。 DIVBUTTONIMG等可能更有用。不过,我认为使用 ... 没有什么坏处。

贾雷特。

I think the "best answer" above, albeit programmatically accurate, does not actually answer the question posed. the question asks how to change the pointer in the mouseover event. I see posts about how one may have an error somewhere is not answering the question. In the accepted answer, the mouseover event is blank (onmouseover="") and the style option, instead, is included. Baffling why this was done.

There may be nothing wrong with the inquirer's link. consider the following html:

<a id=test_link onclick="alert('kinda neat);">Click ME!</a>

When a user mouse's over this link, the pointer will not change to a hand...instead, the pointer will behave like it's hovering over normal text. One might not want this...and so, the mouse pointer needs to be told to change.

the answer being sought for is this (which was posted by another):

<a id=test_link onclick="alert('Nice!');"
       onmouseover="this.style.cursor='pointer';">Click ME!</a>

However, this is ... a nightmare if you have lots of these, or use this kind of thing all over the place and decide to make some kind of a change or run into a bug. better to make a CSS class for it:

a.lendhand {
  cursor: pointer;
}

then:

<a class=lendhand onclick="alert('hand is lent!');">Click ME!</a>

there are many other ways which would be, arguably, better than this method. DIVs, BUTTONs, IMGs, etc might prove more useful. I see no harm in using <a>...</a>, though.

jarett.

国粹 2025-01-02 06:52:29

如果你想在这方面做得更多,这里有一些很酷的东西。在 url 中,您可以使用链接或保存图像 png 并使用路径。例如:

url('assets/imgs/theGoods.png');

下面是代码:

.cursor{
  cursor:url(http://www.icon100.com/up/3772/128/425-hand-pointer.png), auto;
}

所以这只能在 128 X 128 尺寸下工作,任何更大的尺寸都不会加载图像。但您实际上可以使用任何您想要的图像!这将被视为纯 css3 和一些 html。您在 html 中要做的就是

<div class='cursor'></div>

并且仅在该 div 中,该光标才会显示。所以我通常将它添加到 body 标签中。

Here is something cool if you want to go the extra mile with this. in the url, you can use a link or save an image png and use the path. for example:

url('assets/imgs/theGoods.png');

below is the code:

.cursor{
  cursor:url(http://www.icon100.com/up/3772/128/425-hand-pointer.png), auto;
}

So this will only work under the size 128 X 128, any bigger and the image wont load. But you can practically use any image you want! This would be consider pure css3, and some html. all you got to do in html is

<div class='cursor'></div>

and only in that div, that cursor will show. So I usually add it to the body tag.

铁憨憨 2025-01-02 06:52:29

添加 href 属性以使其成为有效的链接和链接return false; 在事件处理程序中以防止其导致导航;

<a href="#" class="menu_links" onclick="displayData(11,1,0,'A'); return false;" onmouseover=""> A </a>

(或者使 displayData() 返回 false 并 ..="return displayData(..)

Add an href attribute to make it a valid link & return false; in the event handler to prevent it from causing a navigation;

<a href="#" class="menu_links" onclick="displayData(11,1,0,'A'); return false;" onmouseover=""> A </a>

(Or make displayData() return false and ..="return displayData(..)

时光倒影 2025-01-02 06:52:29

通过纯CSS解决方案
正如标记为最佳的答案中提到的
不适合这种情况。

本主题中的示例没有正常的静态 href 属性,
它只是JS的调用,所以没有JS它不会做任何事情。

所以最好只用 JS 来开启指针。
因此,

onMouseOver="this.style.cursor='pointer'"

上面提到的解决方案(但我不能在那里发表评论)是这种情况下最好的解决方案。
(但是,一般来说,对于不需要 JS 的普通链接,最好使用没有 JS 的纯 CSS。)

Solution via pure CSS
as mentioned in answer marked as the best
is not suitable for this situation.

The example in this topic does not have normal static href attribute,
it is calling of JS only, so it will not do anything without JS.

So it is good to switch on pointer with JS only.
So, solution

onMouseOver="this.style.cursor='pointer'"

as mentioned above (but I can not comment there) is the best one in this case.
(But yes, generaly, for normal links not demanding JS, it is better to work with pure CSS without JS.)

浅听莫相离 2025-01-02 06:52:29
 <! ––  add this code in your class called menu_links -->
<style> 
.menu_links{
cursor: pointer;
}
</style>

在上面的代码中,[cursor:pointer] 用于访问当您将鼠标悬停在链接上时出现的手形光标。

如果您使用[光标:默认],它将显示通常出现的箭头光标。

要了解有关光标及其外观的更多信息,请单击以下链接:
https://www.w3schools.com/cssref/pr_class_cursor.asp

 <! ––  add this code in your class called menu_links -->
<style> 
.menu_links{
cursor: pointer;
}
</style>

In the above code [cursor:pointer] is used to access the hand like cursor that appears when you hover over a link.

And if you use [cursor: default] it will show the usual arrow cursor that appears.

To know more about cursors and their appearance click the below link:
https://www.w3schools.com/cssref/pr_class_cursor.asp

醉态萌生 2025-01-02 06:52:29
div{cursor: pointer; color:blue}

p{cursor: text; color:red;}
<div> im Pointer  cursor </div> 
<p> im Txst cursor </p> 

div{cursor: pointer; color:blue}

p{cursor: text; color:red;}
<div> im Pointer  cursor </div> 
<p> im Txst cursor </p> 

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文