JavaScript code to stop form submission

前端 未结 12 2066
感情败类
感情败类 2020-11-21 06:40

One way to stop form submission is to return false from your JavaScript function.

When the submit button is clicked, a validation function is called. I have a case i

12条回答
  •  离开以前
    2020-11-21 06:59

    Use prevent default

    Dojo Toolkit

    dojo.connect(form, "onsubmit", function(evt) {
        evt.preventDefault();
        window.history.back();
    });
    

    jQuery

    $('#form').submit(function (evt) {
        evt.preventDefault();
        window.history.back();
    });
    

    Vanilla JavaScript

    if (element.addEventListener) {
        element.addEventListener("submit", function(evt) {
            evt.preventDefault();
            window.history.back();
        }, true);
    }
    else {
        element.attachEvent('onsubmit', function(evt){
            evt.preventDefault();
            window.history.back();
        });
    }
    

提交回复
热议问题