亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

驗證輸入字段后如何提交表單

驗證輸入字段后如何提交表單

白衣非少年 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 關注
  • 115 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號