📌  相关文章
📜  如果存在无效字段,则用于禁用表单提交的示例启动器 JavaScript - 任何代码示例

📅  最后修改于: 2022-03-11 14:59:48.053000             🧑  作者: Mango

代码示例1
// Example starter JavaScript for disabling form submissions if there are invalid fields
(function () {
  'use strict'

  // Fetch all the forms we want to apply custom Bootstrap validation styles to
  var forms = document.querySelectorAll('.needs-validation')

  // Loop over them and prevent submission
  Array.prototype.slice.call(forms)
    .forEach(function (form) {
      form.addEventListener('submit', function (event) {
        if (!form.checkValidity()) {
          event.preventDefault()
          event.stopPropagation()
        }

        form.classList.add('was-validated')
      }, false)
    })
})()