检查下一个元素是否具有特定的类别,转到下一部分

时间:2017-07-11 12:21:38

标签: javascript jquery

我试图让脚本向下滚动到正确的部分。 这是html代码的一小部分:

<div class="page_sections sectionOne">
    <div class="product_options">          
        <input />
    </div>
</div>

<div class="page_sections sectionTwo">
    <div class="product_options">          
        <input />
    </div>
    <div class="product_options">          
        <input />
    </div>
    <div class="product_options">          
        <input />
    </div>
</div>

<div class="page_sections sectionThree">
    <div class="product_options">          
        <input />
    </div>
    <div class="product_options">          
        <input />
    </div>
</div>

脚本的想法是每当有人点击输入(所有选择和广播)时转到下一个product_options。如果未找到产品选项,请转到下一部分。

我认为我非常接近,但似乎无法完成它。你能帮我解决一下:

$(".page_sections :input").change(function(){    

    var next = $(this).closest(".page_sections").nextAll('.page_sections').first();

    if ($(this).closest(".product_options").next('.product_options').length){
        next = $(this).closest(".product_options").next('.product_options');
    }        

    $('html, body').animate({
        scrollTop: $(next).offset().top - 180
    }, 1500);
});

我真的很亲密。用长度做错字 - &gt;长度...

1 个答案:

答案 0 :(得分:0)

我打错了。感谢@PatrickEvans指点我!

相关问题