Javascript HTML菜单:将所选项目图标设置为高位

Javascript HTML菜单:将所选项目图标设置为高位,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有一张图片列表。单击其中一个时,我希望它高亮显示该图像,并将其他图像设置为正常。使用jQuery切换可以做到这一点吗?尝试以下方法: $('img').click(function() { $(".highlight").removeClass("highlight"); //remove the highlight css class from anything that has it $(this).addClass("highlight"); //add the highlig

我有一张图片列表。单击其中一个时,我希望它高亮显示该图像,并将其他图像设置为正常。使用jQuery切换可以做到这一点吗?

尝试以下方法:

$('img').click(function() {
  $(".highlight").removeClass("highlight");  //remove the highlight css class from anything that has it
  $(this).addClass("highlight"); //add the highlight css class to the image that was clicked.
});

请发布到目前为止你的HTML标记是什么样子的?你还需要使用类似:$'.highlight.removeClass'highlight';“将其他人设置为正常。”是的,就在你写评论时捕捉到了这一点。是的,第一行就是这么做的。