【问题标题】:Target all elements before match in jQuery each loop在jQuery每个循环中匹配之前的所有元素
【发布时间】:2014-07-12 14:56:55
【问题描述】:

我想禁用每个函数中匹配元素之前的所有单选按钮。但不知何故,我无法正确定位它们。

我认为最好的方法是,如果我可以执行“定位到现在为止在此每个函数中处理的所有元素”之类的操作。但是因为我找不到这样的东西,所以我想在每次遍历时都尝试一下,但我也无法以这种方式定位它们。

我的 HTML:

<div class="chooseTime">
    Bitte wählen Sie ihre gewünschte Lieferzeit.
    <label class="radio">
        <input type="radio" checked="" value="06:00 Uhr - 10:00 Uhr" name="chooseTime">
        06:00 Uhr - 10:00 Uhr
    </label>
    <label class="radio">
        <input type="radio" value="10:00 Uhr - 14:00 Uhr" name="chooseTime">
       10:00 Uhr - 14:00 Uhr
    </label>
    <label class="radio">
        <input type="radio" value="15:00 Uhr - 17:00 Uhr" name="chooseTime">
        15:00 Uhr - 17:00 Uhr
    </label>
</div>

我的 jQuery:

if($('#Picked_date').val() == $('#Fast').data('lzp_date')) {
    var lzp_time = $('#Fast').data('lzp_time');

    $('.chooseTime input[type=radio]').each(function() {
        var wert = $(this).val();
        if(wert == lzp_time) {
            $(this).prevAll('input[type=radio]').prop('disabled', true);
        }
    })
}

【问题讨论】:

    标签: jquery html radio-button


    【解决方案1】:

    试试

    $(this).parent().prevAll('.radio').find('input[type=radio]').prop('disabled', true);
    

    【讨论】:

    • @Sebsemillia 欢迎 乐于助人 :)
    猜你喜欢
    • 2017-10-07
    • 2019-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-03
    • 2017-08-21
    • 2010-11-16
    相关资源
    最近更新 更多