LoginSignup
3
0

More than 3 years have passed since last update.

javascriptの.submitでif文を使う時のエラー

Last updated at Posted at 2020-02-08
$('#form').submit(function() {

        // form1が空のとき、エラー文を表示してください
        if ( $('.form1').val() === '') {
            $('.error-message-1').text('入力してーーー');
        } else {
            $('.error-message-1').text('');
        }

        return false;
      });

入力してーーー!と表示されない時のエラー。

if ( $('.form1').val() === '')の、クラスの.form1が、
htmlの

<input class="form1" type="text" placeholder="山田 太郎" name="userName">

input内のクラスに名付けないと反応しない。

3
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0