JavaScript Prevent Form Submit

前端 未结 2 1040
遥遥无期
遥遥无期 2021-01-28 20:14

I\'m trying to get my form to not submit when I press the cancel button on my JavaScript dialog.

I have this code:

  $(document).ready(function() {
             


        
2条回答
  •  温柔的废话
    2021-01-28 20:37

    .... .... ....
    $(function() { //this would do the same as button click as both submit the form $(document).on("submit", "#myform", function (e) { var result = confirm("Are you sure you want to log this fault?"); //if cancel is cliked if (!result) { return false; } //if ok is cliked, form will be submitted }); });

提交回复
热议问题