我的 jquery 应该在页面加载时只打开两个 div 中的第一个,但现在它打开了两个。
此外,我已经在我的 CSS 中添加了 .active
类来为事件的 div 链接着色,但它不起作用。
查询
$(document).ready(function () {
$(this).find('.infoexpanderContent').slideDown();
});
$('.infoexpanderHead').click(function () {
$(this).siblings().find('.infoexpanderContent').slideUp();
$(this).find('#infoactive').addClass("active");
$(this).find('.infoexpanderContent').slideDown();
$(this).siblings().find('#infoactive').removeClass("active");
});
CSS
.active {
color: green;
}
对 JS 和 Jquery 很陌生,所以请简单点:)
最佳答案
尝试指定 :first
选择器:
$('.infoexpanderContent:first').slideDown();
顺便说一句,不需要 $(this).find()
方法,因为在 DOM 包装器中,$(this)
引用文档,这在 jQuery 中始终是假定的。
关于javascript - jQuery - 打开 onLoad 的两个 div 之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20702978/