jq判断5个input如果全部为空 , 就alert

<div id="form">
    <input type="text" value="">
    <input type="text" value="">
    <input type="text" value="">
    <input type="text" value="">
    <input type="text" value="">
</div>

<script>
    var inputs = $("#form").children("input"); // jq
    var inputs = document.getElementById("form").getElementsByTagName("input"); // 原生

    // 判断是否全部为空值
    var isEmpty = [].reduce.call(inputs, function (a, b) {
        return a && !b.value;
    }, true);

    // 如果有空值则alert
    isEmpty && alert();
</script>
posted @ 2020-11-27 09:57  Ao_min  阅读(415)  评论(0编辑  收藏  举报