简体   繁体   English

JQuery 弹出窗口未显示

[英]JQuery popup is not showing up

I'm trying to make a popup with JQuery and Javascript when a form is not filled in I want the popup to show up.当未填写表单时,我正在尝试使用 JQuery 和 Javascript 制作一个弹出窗口,我希望弹出窗口显示出来。 But when I don't fill in the form and I click on the submit button its not working and there is no alert showing up.但是当我不填写表格并单击提交按钮时,它不起作用并且没有显示警报。

This is my form code:这是我的表单代码:

Vul deze gegevens in zodat wij voor u kunnen matchen Vul deze gegevens in zodat wij voor u kunnen matchen

<form action="" id="form">

    <label for="locatie"><strong>Naar welke locatie gaat u op vakantie?*</strong></label><br>
    <br>
    <input class="form-input" type="text" id="locatie" name="locatie"required/>

    <br><br>
    <label for="datum"><strong>Welk datum?*</strong></label><br>
    <br>
    <input class="form-input" type="date" id="datum" name="datum" value="19/04-2018"required/>
    <br><br>
    <input class="form-input" id="submit" name="submit" type="submit" value="Versturen">
</form>

This is my Javascript/JQuery code:这是我的 Javascript/JQuery 代码:

 <script language="javascript" type="text/javascript">
    $('#submit').on('click',function()
    {
        if( $('input:required').val().length === 0 ) {
            alert('Vul alle velden in voordat u probeert te verzenden');
            return false;

        }

    });

</script>

In my head:在我脑海中:

So what am I doing wrong?那么我做错了什么? why is there no alert showing when I click on the submit button and the form is not filled in?为什么当我点击提交按钮并且表单没有填写时没有提示显示?

Any kind of help is appreciated任何形式的帮助表示赞赏

You are using css selectors wrong in your code您在代码中错误地使用了 css 选择器

 $('#submit').on('click',function() { if( $('input[type="text"]').val().length === 0 ) { alert('Vul alle velden in voordat u probeert te verzenden'); return false; } });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> <h3>Vul deze gegevens in zodat wij voor u kunnen matchen</h3> <form action="" id="form"> <label for="locatie"><strong>Naar welke locatie gaat u op vakantie?*</strong></label><br> <br> <input class="form-input" type="text" id="locatie" name="locatie" value=""/> <br><br> <label for="datum"><strong>Welk datum?*</strong></label><br> <br> <input class="form-input" type="date" id="datum" name="datum" value="19/04-2018"required/> <br><br> <input class="form-input" id="submit" name="submit" type="submit" value="Versturen"> </form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM