我有一些文本框和一个提交按钮。我使用了 HTML5“必需”验证。它工作正常。现在,当 HTML5 验证未发现任何错误时,我想在单击按钮时调用一个函数。当未提供必填字段时,单击按钮将不会调用该函数。
请您参考如下方法:
您可以使用 form.onsubmit 处理程序。假设表单的 ID 是 form:
var form = document.getElementById("form");
form.onsubmit = function() {
//Pre-submission validation.
//Return true or false based on whether the validation passed.
//return false will prevent the submission the form.
};




