我是jquery的新手。
我有两个with tempCounts as(
SELECT enrollment_id, COUNT(progress_tracker) as countValue
FROM progress_tracker
WHERE progress_tracker.completed = TRUE
group by enrollment_id)
SELECT enrollments.*, users.*,tempCounts.countValue
FROM enrollments, users.*,tempCounts
INNER JOIN users
ON enrollments.user_id = users.id
WHERE enrollments.preview = FALSE
and enrollments.id = tempCounts.enrollment_id
ORDER BY tempCounts.countValue
标记,其类为p
和.angle_up
。
.angle_down
班级有angle_up
个班级。在点击active
时,从.angle_down
移除.active
课程并设置为angle_up
。
在课程.angle_down
时,必须显示带有动画效果的ele
。喜欢切换。
如何实现这一目标。提前谢谢。
active

$(document).on("click", ".angle_up", function () {
$(this).removeClass("active");
var angledwn = $('.angle_down');
angledwn.addClass("active");
var ele = $('.ele');
ele.toggle('5000');
});

.angle_up, .angle_down{
color: #0096C9;
display: none;
}
.angle_up.active, .angle_down.active{
color: #0096C9;
cursor: pointer;
display: block;
}

答案 0 :(得分:2)
你的html中有输入错误。类为angle_up
而不是angle.up
。
为您的.angle
和.angle_up
添加一个额外的公共课.angle_down
,并将该类用作点击事件的选择器。
$(document).on("click", ".angle", function () {
var angledwn = $('.angle').not('.active');
$(this).removeClass("active");
angledwn.addClass("active");
var ele = $('.ele');
ele.toggle('5000');
});
.angle_up, .angle_down{
color: #0096C9;
display: none;
}
.angle_up.active, .angle_down.active{
color: #0096C9;
cursor: pointer;
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="angle angle_up active">First</p>
<p class="angle angle_down"> Second</p>
<p class="ele">To hide to display</p>
答案 1 :(得分:1)
你不需要逐个选择元素来实现这个,只需通过标签p选择并使用.not()在未被点击的P元素上添加类。
$(document).on("click", "p", function () {
$(this).removeClass("active");
$("p").not(this).addClass("active");
var ele = $('.ele');
ele.toggle('5000');
});
&#13;
.angle_up, .angle_down{
color: #0096C9;
display: none;
}
.angle_up.active, .angle_down.active{
color: #0096C9;
cursor: pointer;
display: block;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="angle_up active">First</p>
<p class="angle_down"> Second</p>
<p class="ele">To hide to display</p>
&#13;
P.S:<p class="angle up active">First</p>
你需要纠正它,它应该是
<p class="angle_up active">First</p>
你在班级名称中缺少_