所以我有這個注冊表單,我正在驗證輸入字段,如果它們是空白的,如果它們使用正確的模式,但我收到提交按鈕的錯誤,提交按鈕不起作用 未捕獲類型錯誤:無法將屬性“禁用”為null我希望有人可以告訴我如何使用從驗證中獲取的信息來提交表單P.S如果你有無論如何優化代碼,我會非常感激這里是<h1>Signup</h1><form action="#" id="form_id"> <p>Username</p> <input type="text" id="user" placeholder="Enter Username" pattern="^[a-zA-Z0-9]{8,}$" title="please enter a username with only Letters and numbers[0-9]"> <p>Password</p> <input name="password" id="password" type="password" placeholder="Enter Password" pattern="(?=.*[a-zA-Z].*)(?=.*[A-Z])(?=.*[0-9])(?=.*[#@!%])[a-zA-Z0-9#@!%]{6,}" title="please enter a password with at least 1 capital letter and one special from[#@!%]" /> <p>confirm password</p> <input type="password" name="confirm_password" id="confirm_password" placeholder="confirm Password" onkeyup='check();' /> <span id='message'></span> <br> <input type="submit" id="Signup" value="Signup" onclick= "inputchecker()" disabled ></form>`這里是 js 和 jq $('#password').on('input', function(e) { this.setCustomValidity('') if ($(this).val() >=1) { this.setCustomValidity('') } this.reportValidity(); e.target.checkValidity(); }) $('#user').on('input', function(d) { this.setCustomValidity('') if ($(this).val() >=1) { this.setCustomValidity(''); } this.reportValidity(); d.target.checkValidity(); }) $('#user').on('input', function(d) { this.setCustomValidity('') if ($(this).val() =='') { this.setCustomValidity("please fill out the field"); } this.reportValidity(); d.target.checkValidity(); }) $('#password').on('input', function(e) { this.setCustomValidity('') if ($(this).val() =='' ) { this.setCustomValidity("please fill out the field") } this.reportValidity(); e.target.checkValidity(); }); }}
驗證輸入字段后如何提交表單
白衣非少年
2022-08-18 10:40:15
