不知道这里有什么问题.所有其他代码工作正常并且已经永远但现在我只是尝试将另一个类添加到您单击的元素并且该函数仍然正常工作它似乎忽略了我的.addClass().
$('.item-main-section, .item-status').click( function () {
var slideHeight = $(this).parent().children('.item-slide-section').height();
//Not Doing Anything
if ($('item-slide-section').hasClass('current-open')) {
$('item-slide-section').removeClass('current-open');
}
$(this).parent().children('item-slide-section').addClass('current-open');
//Not Doing Anything ^^^^
if ($(this).parent().height() > 50) {
$(this).parent().animate({height: '50px'}, 300);
$(this).parent().children('item-slide-section').animate({bottom: '0px'}, 300);
} else {
$(this).parent().animate({height: slideHeight + 50 + 'px'}, 300);
$(this).parent().children('item-slide-section').animate({bottom: slideHeight - 5 + 'px'}, 300);
$(this).parent().siblings('.item-wrapper').animate({height: '50px'}, 300);
$(this).parent().siblings('.item-wrapper').children('item-slide-section').animate({bottom: '0px'}, 300);
}
});
Run Code Online (Sandbox Code Playgroud)
你.在选择器中忘了一个.
这里:
$(this).parent().children('.item-slide-section').addClass('current-open');
Run Code Online (Sandbox Code Playgroud)
和这里:
if ($('.item-slide-section').hasClass('current-open')) {
$('.item-slide-section').removeClass('current-open');
}
Run Code Online (Sandbox Code Playgroud)
一般来说,像这样的问题不适合这个网站.
考虑debugger;下次在有问题的行上方(或在其下方)使用语句并检查选择器是否实际匹配任何内容.
如果你这样做了,你可以看到选择的长度为0,因此,元素没有子元素.
所以基本上,下次你遇到这类问题时,先问SO:
debugger;声明.如果您不知道如何使用调试器单步执行代码,请考虑阅读http://discover-devtools.codeschool.com/.console.log在它们之间使用以验证您认为您对环境的了解.