简体   繁体   English

如何从<span>悬停中</span>删除文本下划线(我自己设置的下划线) <span>?</span>

[英]How do I remove the text underline (that I set myself) from a <span> on hover?

I want to have a link but I want to have a jQuery event fire onclick so I am using a <span> with an id instead of a link so I can listen for the click event. 我想要一个链接,但是我想让jQuery事件触发onclick,因此我使用的是带有ID的<span>而不是链接,以便可以监听click事件。

I want to make the <span> look like a link so: 我想使<span>看起来像一个链接,这样:

  1. The cursor should show a hand when the <span> is hovered 悬停<span>时,光标应显示一只手
  2. The <span> should be underlined and blue <span>应加下划线并为蓝色

This works fine in CSS, but I want to remove the underline when I hover. 这在CSS中工作正常,但是我想在悬停时删除下划线。 How would I do this in CSS? 如何在CSS中执行此操作?

span:hover {
    text-decoration: none;
}

"i want to have a link but i want to have jquery event fire onclick so i am using a span instead of a link" “我想要一个链接,但我想让jquery事件触发onclick,所以我使用的是跨度而不是链接”

Why not just place the click event on the <a href='whatever'> ? 为什么不将click事件放置在<a href='whatever'>

  // Use the actual ID instead of 'a'.
$('a').click(function( event ) {
    event.preventDefault(); // Prevent the link from being followed
    // do something
});

Then change the text-decoration of the <a> on using the pseudo :hover 然后使用伪:hover更改<a>的文本修饰

a:hover {
    text-decoration:none;
}

If you do it on a <span> instead, the :hover won't work in IE6. 如果改为在<span> ,则:hover在IE6中不起作用。

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

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