停止表单提交的一种方法是从您的JavaScript函数中返回false。
当点击提交按钮时,会调用一个验证函数。我在表单验证中有一个条件。如果满足该条件,我会调用一个名为returnToPreviousPage();的函数。
function returnToPreviousPage() {
window.history.back();
}
我正在使用JavaScript和Dojo Toolkit。
与其返回到上一页,它会提交表单。我该如何中止此提交并返回到上一页?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
使用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(); }); }