jquery check textbox empty

我有一個登入用的 form, 用 bootstrap 做的, 希望可以檢查 account 欄位是否有填值.

if (inp.val().length > 0) {
    // do something
}

if you want anything more complicated, consider regex or use the validation plugin which takes care of this for you.

在檢查到登入失敗, 或無填值, 有二種處理方式, 一個是彈 modal dialog, 一個是用 danger text, 如果不是太重大的提醒, 應該使用 danger text, 使用方法:

<div class="text-danger" id='fail-message'>your message here.</div>

我的登入 script:

  let do_signin_flag = true;
  $("#fail-message").html("");
  if($("#account").val().length==0){
    $("#fail-message").html("Account is required.");
    $("#account").focus();
    do_signin_flag=false;
  }

我使用的範例:
https://getbootstrap.com/docs/5.3/examples/sign-in/


How to Set the Value of Input Text Box using jQuery

範例:

<script>
$(document).ready(function(){
    $("#myInput").val("https://");
});
</script>

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *