jquery - 默认链接颜色保持事件状态,直到鼠标单击另一个链接

标签 jquery html css

<分区>

当您进入该站点时,我的默认链接颜色处于事件状态,但当鼠标单击另一个链接并且新的当前页面现在处于事件状态时,我似乎无法将其从事件状态中删除。这是我的代码。

JS

$("a").on("click", function() { 
    $(".active").removeClass("active"); 
});

CSS

.active{ 
    color: #ffff00 
    !important; 
}

a { 
    text-decoration: none; 
    z-index: 5; 
    font-family: arial, "Trebuchet MS"; 
    cursor: pointer; 
    color: #2777A3; 
}

HTML

<a href="http://www.pro.com/" target="_self" class="active">Home</a>`

home page active by default but when clicked on another link, new link does not show active color

最佳答案

$("a").click(function() {
    $(".active").removeClass("active");
    $(this).addClass("active");
});

http://jsfiddle.net/UbVVH/1/

关于jquery - 默认链接颜色保持事件状态,直到鼠标单击另一个链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14405552/

上一篇:html - 无法使用替换从 HTML 中删除不需要的字符

下一篇:html - <a href> 从 html 文件中发送电子邮件

相关文章:

javascript - 如何使用 jquery/js 使内容在悬停时显示在另一个下方(如 <li> 列表)

javascript - 多个条件到一个复选框

html - HTML中不关闭标签和属性的实际问题是什么

html - 使用纯 CSS 获取标题行和标题列的边框

php - <?php language_attributes(); ?> 在 html 标签上

jquery - 当该部分可能有多个单词时,如何用另一部分替换 href 的特定部分?

jquery-ui - jQuery 1.4.2 - "Object doesn' 在 Internet Explorer 8 中不支持此属性或方法

android - 当使用绝对定位元素构建页面时,WebKit 似乎错误计算了窗口/主体大小,如何修复?

html - 如何使表格隐藏在所有电子邮件客户端中

javascript - jQuery 查找并列出特定 DIV 中 UL 内的所有 LI 元素