Count empty input field[]?

后端 未结 3 870
我寻月下人不归
我寻月下人不归 2021-01-07 14:44
相关标签:
3条回答
  • 2021-01-07 14:54
    $('#uploadimages input:file[value=""]').length
    
    0 讨论(0)
  • 2021-01-07 14:55

    Accepted approach of Murtaza unfortunatelly doesn't work for me. I don't know why. https://jsfiddle.net/7vLrhqyw/

    This works:

    $(".count").click(function () {
        var count=0;
        $('#uploadimages input:file').each(function(){
           if($(this).val()=="")count++; 
        });
        alert(count);
    
    });
    
    0 讨论(0)
  • 2021-01-07 15:05

    Working with your example

    <ul id="uploadimages">
        <li><input type="file" name="gallery[]" id="upload1"/></li>
        <li><input type="file" name="gallery[]" id="upload2"/></li>
        <li><input type="file" name="gallery[]" id="upload3"/></li>
        <li><input type="file" name="gallery[]" id="upload4"/></li>
    </ul>
    
    <input type="button" value="click" class="count"/>
    

    Script in document.ready

    $(".count").click(function(){
    var count = $('#uploadimages input:file[value=""]').length
    alert(count);
    
    })
    
    0 讨论(0)
提交回复
热议问题