2016-04-03 27 views
-3

引数[i]を使用してすべての関数引数の値をループして電子メールの検証を簡素化したいが、 "undefined"を返す。関数引数の値を取得する方法は?

function checkInputRequired(companyNameValue, contactNameValue, publisherEmailValue, publisherEmailConfirmValue) 
    { 
     // The arguments object is an Array-like object corresponding to the arguments passed to a function. 
     for (var i = 0; i < arguments.length; i++) 
     { 
      // print out 4 undefined 
      console.log(arguments[i]); 
     } 
    } 
+0

どの引数をテストしていますか?私に教えてはいけない、あなたは、任意の引数を提供していない... – Xufox

答えて

1

チェックこのアウト

function checkInputRequired(companyNameValue, contactNameValue, publisherEmailValue, publisherEmailConfirmValue) 
    { 
     // The arguments object is an Array-like object corresponding to the arguments passed to a function. 
     for (var i = 0; i < arguments.length; i++) 
     { 
      // print out 4 undefined 
      console.log(arguments[i]); 
     } 
    } 

checkInputRequired('ddd','bbbbb','sssss','dddddddddd'); 

関数を呼び出すとき、それはそれ以外の場合は未定義のデフォルト値を表示値が表示されます。

+0

これは私が今まで見た中で一番簡単な答えです、笑 – JordanHendrix

+1

@Omarjmhのおかげ!!!!!!!!!!!!!!! –

+0

@SantoshRamKunjirハハありがとう。実際には、コードを間違った方法で構造化しました。フォームの提出時に.val()をつかんでいないので、値を正しく渡したと思っていましたが、引数オブジェクトと何か関係があると思いました。ケースが閉まった。 –

関連する問題