元素删除类:无法从使用jQuery
<div class="row">
<img src="image.png" class="download-image regular-image" />
<div class="options">
<p>download</p>
</div>
<img src="image.png" class="download-image regular-image" />
<div class="options">
<p>download</p>
</div>
和下面的代码来处理它(它改变了形象,基本上它是一个活跃的状态实现):
此代码运行良好,但通过单击元素删除.current
类时遇到问题。 g虽然我通过点击页面的任何地方像这样实现的:
$("html").click(function() {
$(".options").hide();
$(".download-image").removeClass('current').attr("src", "image.png");
$(".download-image").hover(function() {
$(this).attr("src", "image2.png");
}, function() {
$(this).attr("src", "image.png");
});
});
这一块不正是我想要的,但我也想有活动图像相同的行为了。我的尝试: 1.添加.current
到html
点击事件 2.创建相同的功能,但对于.current
类 3.使用.on('click', '.current', function()
4.去就像这样:以上
$('.current').click(function() {
$(this).removeClass('current');
}
没有为我工作。我错在哪里?任何帮助,将不胜感激。
侦听器的回调函数中的this关键字附有该事件。你想要的HTML元素。尝试这个。 $('。current')。on('click',function(e){$(e.target).removeClass('current');}在移动设备上,atm格式是ass –
你可以验证'$ )'解决了使用开发人员工具的问题?我认为我前一阵面临同样的问题,在这种情况下'$(this)'不是解析为'img'标签,而是周围的'div'。 – DotBert
@DotBert it指向不完全是他想要的事件 –