jquery - 图片 :active border not working

标签 jquery css

我有 5 张内嵌 1 像素边框的图片。我希望悬停和激活边框具有不同的颜色。

我使用了下面的代码

$('img').click(function(){ $(this).toggleClass('orangeborder'); });

为我的图像添加边框。它工作完美。但我有 5 张图片,单击时所有图片上的边框都保留。我只想在最后单击的图像上有边框。当我单击第一个图像具有边框时,当我单击第二个图像时仅在第二个图像上具有边框,而不是在两个图像上具有边框。我该怎么做?

谢谢!

最佳答案

首先从所有图像中删除类,然后将其添加到被点击的图像中。

$('img').click(function(){ 
    $('img').removeClass('orangeborder');
    $(this).addClass('orangeborder'); 
});

关于jquery - 图片 :active border not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25888820/

相关文章:

jquery - 是否有可能让多个表单与一个 ajax post 函数一起使用

jquery - $(this).find ('input[type="提交"] :not(. 取消), 按钮').click(function () - 这是什么?

javascript - jQuery 语法错误 - 意外的标记

jquery - 使用 JQuery 更改跨度文本的颜色

html - Bootstrap 模式无法与 Bootstrap 卡一起正常工作

css - W3C 官方最新推荐的 HTML 和 CSS 版本是什么,用于 web 开发?

css - Google 字体在 Firefox 中不显示

javascript - 在ajax返回的html上调用jquery函数

jquery - 将绝对元素始终置于其他元素之下

CSS 空白 :pre always renders a horizontal scrollbar in firefox