[英]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.