为了账号安全,请及时绑定邮箱和手机立即绑定

验证输入字段后如何提交表单

验证输入字段后如何提交表单

白衣非少年 2022-08-18 10:40:15
所以我有这个注册表单,我正在验证输入字段,如果它们是空白的,如果它们使用正确的模式,但我收到提交按钮的错误,提交按钮不起作用 未捕获类型错误:无法将属性“禁用”为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();            });    }}
查看完整描述

1 回答

?
隔江千里

TA贡献1906条经验 获得超10个赞

更改为document.getElementById('Sign_up').disabled=false;document.getElementById('Signup').disabled=false;

它显示错误,因为输入 ID 错误。使用上面的更改,它将能够根据其ID找到正确的元素。

<input type="submit" id="Signup"  value="Signup" onclick= "inputchecker()" disabled >


查看完整回答
反对 回复 2022-08-18
  • 1 回答
  • 0 关注
  • 110 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号