【发布时间】:2013-03-22 13:16:54
【问题描述】:
有什么方法可以将类添加到多个链接?我有两个不同的 div 包含相同的链接集;单击链接应将相同的类应用于另一个 div 集中的“等效”链接。
<style>
.one{margin:70px 0}
.one a{ margin:10px; padding:5px 10px; background-color:green; text-decoration: none; color:white}
.selected{background-color: yellow;}
</style>
<div class="one">
<a href="#first">1</a><a href="#second">2</a><a href="#third">3</a>
</div>
<div class="two">
<a href="#first">1</a><a href="#second">2</a><a href="#third">3</a>
</div>
<script>
$("a.one").click(function() {
$(this).addClass(".selected").filter(':first').click();
});
</script>
【问题讨论】:
-
请您再解释一下吗?你想要的最终结果应该是什么?
-
我在第一个 div 中有 10 个链接,在第二个 div 中有 10 个链接。如果我单击 div one 中的第一个链接。类应应用于该链接,并且同一时间类应用于第二个 div 第一个链接。我希望问题得到解决。