[英]Multiple selectors using this and variable
我在網站上創建了一個快速標簽欄。 單擊時,jQuery抓取數據幻燈片並使用該信息查找匹配的ID並應用一個類。
<div class="service-link" data-slide="#post-123">Click Me</div>
當我在同一行上使用“ this”和target時,“ target”沒有將活動類應用於它。
$(this, target).addClass("active");
如果我使用兩行,它將起作用。 有人知道我為什么不能使用一行嗎?
$(this).addClass("active");
$(target).addClass("active");
完整的工作腳本-
$(".service-link").click(function(){
var target = $(this).data("slide");
$(".service-type-slide, .service-link").removeClass("active");
$(target).addClass("active");
$(this).addClass("active");
})`
我覺得:
$(this, target)
將嘗試在目標上下文中找到節點元素( 此節點指代)。 但它不會找到它,因為目標不包含該元素
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.