3

div 内のすべてのドロップダウン ボックスが選択されたときに通知する単純な関数を作成しようとしています。問題は、フィルターが何も選択していないため、長さが常に 0 であるように思われます。何が起こっているのでしょうか? これが私がこれまでに持っているものです:

JQuery

$('.month, .year').change(function () {
    var $this = $(this);
    var $empty = $this.parent().parent().find('.month, .year').filter('[value=""]').length;
    if ($empty == 0) {
        alert('there are no empty dropdowns');
    }
});

HTML

<form class="date_catcher">
    <div style="display:inline;" class="start">
        <select class='input-small month' name='month'>
            <option value='' selected='selected'>---</option>
            <option value='0'>Jan</option>
        </select>
        <select class='input-small year' name='year'>
            <option value='' selected='selected'>----</option>
            <option value="2012">2012</option>
        </select>
    </div>

    <div style="display:inline;" class="end">
        <select class='input-small month' name='month'>
            <option value='' selected='selected'>---</option>
            <option value='0'>Jan</option>
        </select>
        <select class='input-small year' name='year'>
            <option value='' selected='selected'>----</option>
            <option value="2012">2012</option>
        </select>
    </div>
</form>

ご協力いただきありがとうございます!

4

2 に答える 2

0
$(".date_catcher select").change(function(){
    $empty = $(".date_catcher option").filter(":selected").filter("[value='']").size();
    if($empty == 0){
        alert("there are no empty dropdowns");
    }
});
于 2013-05-24T16:22:57.757 に答える