迭代选择器 javascript 旁边的所有元素



嗨,我有一个选择框,在不同的元素中具有相同的类超级属性选择,例如

<dd class="clearfix swatch-attr" style="display: none;">
    <div class="input-box">
        <select name="super_attribute[327]" id="attribute327" class="required-entry super-attribute-select no-display swatch-select"
            style="display: none;">
    <option value="">Choose an Option...</option><option value="2178" price="0" data-label="not specified" selected="selected">Not Specified</option></select>
    </div>
</dd>
<dd>
    <div class="input-box field__input-wrapper">
        <select name="super_attribute[481]" id="attribute481" class="required-entry super-attribute-select field__input field__input--select"
            style="pointer-events: none;">
    <option value="">Choose an Option...</option><option value="5531" price="0" data-label="intel core i5">Intel Core I5</option></select>
    </div>
</dd>
<dd>
    <div class="input-box field__input-wrapper">
        <select name="super_attribute[500]" id="attribute500" class="required-entry super-attribute-select field__input field__input--select"
            style="pointer-events: none;">
    <option value="">Choose an Option...</option><option value="5828" price="0" data-label="8 gb ddr3">8 GB DDR3</option></select>
    </div>
</dd>
<dd>
    <div class="input-box field__input-wrapper validation-passed">
        <select name="super_attribute[542]" id="attribute542" class="required-entry super-attribute-select field__input field__input--select validation-passed">
    <option value="">Choose an Option...</option><option value="9396" price="424" data-label="3.3 ghz">3.3 GHz</option><option value="9393" price="300" data-label="3.2 ghz">3.2 GHz -BHD 124.00</option><option value="9628" price="84" data-label="3.1 ghz">3.1 GHz -BHD 340.00</option><option value="9626" price="0" data-label="2.8 ghz">2.8 GHz -BHD 424.00</option></select>
    </div>
</dd>
<dd style="display: block;">
    <div class="input-box field__input-wrapper">
        <select name="super_attribute[543]" id="attribute543" class="required-entry super-attribute-select field__input field__input--select"
            style="pointer-events: none; display: block;">
    <option value="">Choose an Option...</option><option value="9857" price="0" data-label="amd radeon r9 290x">AMD Radeon R9 290X</option></select>
    </div>
</dd>
<dd class="last">
    <div class="input-box field__input-wrapper">
        <select name="super_attribute[629]" id="attribute629" class="required-entry super-attribute-select field__input field__input--select"
            style="pointer-events: none;" disabled="">
    <option value="">Choose an Option...</option><option value="13288" price="0" data-label="1 tb">1 TB</option></select>
    </div>
</dd>

我有在更改选择值时触发的js函数

jQuery('.super-attribute-select').on('change', function () {jQuery('.super-attribute-select').each(function () {}}

当任何选择值发生变化时,我正在使用 .each 迭代这些选择框。

但是我只想迭代那些在此更改选择之后出现的选择框,而不是从头到尾遍历所有选择。就像我更改了第三个选择框循环迭代必须从第三个而不是第一个开始。我已经尝试过.nextAll()但它只迭代兄弟姐妹,在我的情况下不起作用。

> 你可以这样做

jQuery(this).closest('dd').nextAll('dd').find('.super-attribute-select');

最新更新