元素刪除類:無法從使用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指向不完全是他想要的事件 –