让我们说,
<div class="container">
<div class="main-sectors">
<a href="#" class="sector-active">Name1</a>
<a href="#" class="p-l-35">Name2</a>
<a href="#" class="p-l-35">Name3</a>
<a href="#" class="p-l-35">Name4</a>
<a href="#" class="p-l-35">Name5</a>
</div>
</div>
&#13;
此处,如何点击每个class="sector-active"
元素时如何应用a
?
答案 0 :(得分:1)
试试此代码
$('.main-sectors a').click(function(){
$('a').removeClass('sector-active');
$(this).addClass('sector-active');
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="main-sectors">
<a href="#" class="sector-active">Name1</a>
<a href="#" class="p-l-35">Name2</a>
<a href="#" class="p-l-35">Name3</a>
<a href="#" class="p-l-35">Name4</a>
<a href="#" class="p-l-35">Name5</a>
</div>
</div>
答案 1 :(得分:0)
试试这段代码:
$("a").on("click", function() {
$("a").addClass("sector-active");
});