Jquery 如果窗体为空,则阻止启动modal

Jquery 如果窗体为空,则阻止启动modal,jquery,forms,modal-dialog,submit,required,Jquery,Forms,Modal Dialog,Submit,Required,我在html的页脚中有一个表单,指向一个form.php,它将字段信息传递到电子邮件中 (并滚动至底部) 我还有一个在提交后出现的感谢模式,脚本将提交延迟到5秒(允许用户阅读感谢模式) 问题是,如果用户将字段留空并按下submit按钮,模式仍会显示,我希望避免出现这种情况 如果字段为空,我试图禁用该按钮,但它不起作用 表格代码 <form method="post" action="form.php" class="form-horizontal" id="foot

我在html的页脚中有一个表单,指向一个form.php,它将字段信息传递到电子邮件中

(并滚动至底部)

我还有一个在提交后出现的感谢模式,脚本将提交延迟到5秒(允许用户阅读感谢模式)

问题是,如果用户将字段留空并按下submit按钮,模式仍会显示,我希望避免出现这种情况

如果字段为空,我试图禁用该按钮,但它不起作用

表格代码

            <form method="post" action="form.php" class="form-horizontal" id="footer-contact-form">

                <fieldset>

                <!-- Text input-->
                <div class="form-group">
                  <div class="col-md-12">
                  <input id="name" name="name" type="text" placeholder="Full Name" class="form-control input-md" required>

                  </div>
                </div>

                <!-- Text input-->
                <div class="form-group">
                  <div class="col-md-12">
                  <input id="email" name="email" type="text" placeholder="Email Address" class="form-control input-md" required>

                  </div>
                </div>

                <!-- Text input-->
                <div class="form-group">
                  <div class="col-md-12">
                  <input id="subject" name="subject" type="text" placeholder="Subject" class="form-control input-md" required>

                  </div>
                </div>

                <!-- Textarea -->
                <div class="form-group">
                  <div class="col-md-12">                     
                    <textarea class="form-control" id="message" type="text" name="message" required placeholder="Message"></textarea>
                  </div>
                </div>

                <!-- Button -->
                <div class="form-group">
                  <div class="col-md-12">
                    <button id="Send-footer" type="submit" name="Send" class="btn btn-default btn-footer" data-toggle="modal" data-target="#thanks">Send</button>
                  </div>
                </div>

                </fieldset>
                </form>

发送
脚本延迟提交

<script type="text/javascript">
$('#footer-contact-form').submit(function (e) {
    var form = this;
    e.preventDefault();
    setTimeout(function () {
        form.submit();
    }, 5000); // in milliseconds
});
 <script>
$(document).ready(function (){
    validate();
    $('#name, #email, #subject, #message').change(validate);
});

function validate(){
    if ($('#name').val().length   >   0   &&
        $('#email').val().length  >   0   &&
        $('#subject').val().length  >   0   &&
        $('#message').val().length    >   0) {
        $("#Send-footer").prop("disabled", false);
    }
    else {
        $("#Send-footer]").prop("disabled", true);
    }
}

$(“#页脚联系表”)。提交(功能(e){
var form=此;
e、 预防默认值();
setTimeout(函数(){
表单提交();
},5000);//以毫秒为单位
});

脚本我试图禁用“提交”按钮(这目前对我不起作用,该按钮永远不会再次启用)


$(文档).ready(函数(){
验证();
$(“#姓名,#电子邮件,#主题,#消息”)。更改(验证);
});
函数验证(){
如果($('#name').val().length>0&&
$('#email').val().length>0&&
$('#subject').val().length>0&&
$('#message').val().length>0){
$(“#发送页脚”).prop(“已禁用”,false);
}
否则{
$(“#发送页脚]”).prop(“已禁用”,true);
}
}


任何帮助都将不胜感激。

也许试试这个?我不确定在没有“()”的情况下调用validate函数是否有效,因此我认为对document.ready调用validate是唯一一次调用它

$(document).on('change', '#name, #email, #subject, #message', function()
{
    validate();
}); 

实际上,这个脚本用于禁用submit按钮

 <script>
$('#Send-footer').attr('disabled', true);
$('input:text').keyup(function () {
    var disable = false;
       $('input:text').each(function(){
            if($(this).val()==""){
                 disable = true;                
            }
       });
  $('#Send-footer').prop('disabled', disable);
});

$(“#发送页脚”).attr('disabled',true);
$('input:text').keyup(函数(){
var disable=false;
$('input:text')。每个(函数(){
if($(this).val()==“”){
禁用=真;
}
});
$(“#发送页脚”).prop('disabled',disabled);
});

您是否尝试过查看它是否真的进入if/else?