有没有更好的方法来改变光标?我做对了吗?
前几天我刚刚使用了一些 javascript,之前,我知道如何让它显示光标的唯一方法就是这样做:
1:
<a href="javascript:" onClick="myfunction()"></a>
但我决定找到一些其他方法来做到这一点。不想让我的 css 乱七八糟,我将其添加到我的样式表中:
2:
a{
cursor:pointer
}
我不会在其他任何地方设置非链接锚点的样式。可以设置非链接锚点的样式吗?
3:
或者有没有一种方法我应该用 javascript 来完成它,这比上面列出的两种方法更好。
I was just using some javascript the other day, and previously, the only way I knew how to get it to display the cursor was to do this:
1:
<a href="javascript:" onClick="myfunction()"></a>
But I decided to find some other ways to do it. Not wanting to have my css messy and all over the place, I added this to my stylesheet:
2:
a{
cursor:pointer
}
I'm not styling non-link anchors anywhere else. Is it okay to style non-link anchors?
3:
Or is there a way I should being doing it with javascript that's better then the two ways listed above.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嘿,有些浏览器将光标称为指针,其他浏览器将其称为手(忘记了哪个)。所以你要做的是
编辑:
我喜欢制作一个名为pointable的css样式,并将其应用到我想要pointable的任何元素上。
Hey some browsers call the cursor a pointer, others call it a hand (forgot which ones which). So what you have to do is
Edit:
I like to make a css style called pointable and applying it to whatever elements I want pointable.
只要这不会妨碍您在页面上任何其他位置设置
标记的样式,这就是最好的方法。
As long as this does not get in the way of how you style the
<a>
tag anywhere else on your page this is the best way to do it.所有
标记都应具有
href
属性,即使该属性为空或显示javascript:;
。所以我推荐选项1。
All
<a>
tags should have anhref
attribute even if it is blank or saysjavascript:;
.So I recommend option 1.