0

ユーザーがボタン ( ) をクリックしたときに JavaScript で関数を呼び出そうとしていますonclick="Website.submit()"が、コードが機能しません。

Chrome で次のエラーが発生します。

キャッチされていない TypeError: 不正な呼び出し

Chrome では、次の行がjquery.jsエラーの原因として強調表示されます。

// If value is a function, invoke it and return its value

value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );

開発者パネルの [コンソール] タブ (F12) のより詳細なエラー:

キャッチされていない TypeError: Chrome での不正な呼び出し

コードは次のとおりです。

var Website = {

  submit: function () {

    var stap1 = $('#stap1').val();
    var stap2 = $('#stap2').val();
    var stap3 = $('#stap3').val();
    var letop = $('#letop').val();

    if (stap1.length == 0) {
      $('#error2').show();
      $('#the_error2').html('Je moet alle velden invullen om door te gaan.');

      $('#stap1').css({
        'border-width': '1px',
        'border-color': 'red'
      });
    }

    if (stap2.length == 0) {
      $('#error2').show();
      $('#the_error2').html('Je moet alle velden invullen om door te gaan.');

      $('#stap2').css({
        'border-width': '1px',
        'border-color': 'red'
      });
    }

    if (stap3.length == 0) {
      $('#error2').show();
      $('#the_error2').html('Je moet alle velden invullen om door te gaan.');

      $('#stap3').css({
        'border-width': '1px',
        'border-color': 'red'
      });
    }

    if (letop.length == 0) {
      $('#error2').show();
      $('#the_error2').html('Je moet alle velden invullen om door te gaan.');

      $('#letop').css({
        'border-width': '1px',
        'border-color': 'red'
      });
    }

    if (stap1.length !== 0 && stap2.length !== 0 && stap3.length !== 0 && letop.length !== 0) {

      $.post(General.url + "/pages/website_check.php", {
        naam: naam,
        subdomein: subdomein,
        stap1: stap1,
        stap2: stap2,
        stap3: stap3,
        letop: letop
      }, function (result) {

        if (result == 1) {
          $('#error2').show();
          $('#the_error2').html('Deze naam is al in gebruik. Ga snel terug en kies een andere.');

          $('#error').show();
          $('#the_error').html('Deze naam is al in gebruik. Kies een andere.');

          $('#naam').css({
            'border-width': '1px',
            'border-color': 'red'
          });

        } else {
          if (result == 2) {
            $('#error2').show();
            $('#the_error2').html('Dit subdomein is al in gebruik. Ga snel terug en kies een andere.');

            $('#error').show();
            $('#the_error').html('Dit subdomein is al in gebruik. Kies een andere.');

            $('#subdomein').css({
              'border-width': '1px',
              'border-color': 'red'
            });
          }
        }
      });
    }
  }

};
4

1 に答える 1