HTML5 required attribute not working

前端 未结 2 953
余生分开走
余生分开走 2021-01-29 11:27

I want to create a email contact form without refreshing the page. So i added jquery im my html file. I used html required attribute ti check if the fields are empty. But when i

2条回答
  •  深忆病人
    2021-01-29 12:18

    You are sending the AJAX request when the user clicks on the button, not when they submit the form. Change .click() to .on('submit') and attach it to the form, not the button:

    $('#mycontactform').on( 'submit', function () {
        ...
    

    Demo: http://jsfiddle.net/QjPka/

提交回复
热议问题