它在 Chrome 和 Edge 中完美运行,但在 IE11 中不起作用。我尝试删除 novalidate,但它使验证仅在 IE11 中有效。这是我的代码:<form class="m-t needs-validation" id="needs-validation" role="form" action="index.html" novalidate> <div class="form-group"> <input type="text" class="form-control" placeholder="Username" required> <div class="invalid-feedback"> Please enter a valid username. </div> </div> <div class="form-group"> <input type="password" class="form-control" placeholder="Password" required> <div class="invalid-feedback"> Please enter a valid password. </div> </div> <button type="submit" class="btn btn-primary block full-width m-b">Login</button></form>javascript 中的事件监听器如下所示:<script> (function() { 'use strict'; window.addEventListener('load', function () { var forms = document.getElementsByClassName('needs-validation'); var validation = Array.prototype.filter.call(forms, function(form) { form.addEventListener('submit', function (evt) { if (form.checkValidity() === false) { event.preventDefault(); event.stopPropagation(); } form.classList.add('was-validated'); }, false); }); }, false); })();</script>我的代码是否做错了以及如何修复它,以便它也可以在 IE11 中工作?
添加回答
举报
0/150
提交
取消