2017-03-03 99 views
0

進出口創造了我的步向導形式的一些驗證輸入,但得到一個錯誤,當我嘗試驗證輸入字段,它給我的錯誤:步驟嚮導驗證

Uncaught TypeError: input_single[i].val is not a function 

這裏是我的JS:

$(".next-step").click(function (e) { 

     //Make some validation 
     var curStep = $(this).closest(".tab-pane"), 
      curStepBtn = curStep.attr("id"), 
      isValid = true; 

     var input_single= curStep.find("input[type='text']"); 

     var temp = 0; 

     //clean all 
     $('.error-list').html(""); 

     if(input_single.length > 0){ 

      for(var i=0; i< input_single.length; i++){ 

       if (input_single[i].val() != ""){ 
        temp = temp+1; 
       } 
      } 

      if(temp === 0){ 
       isValid = false; 
       $('.error-list').append("<li class='error'><i class='fa fa-angle-right'></i> Required field</li>"); 
      } 
     } 


     } 

回答

0

您在這裏訪問DOM元素input_single[i].val() != ""並使用VAL()作爲是一個DOM屬性,但實際上是一個jQuery函數。

在你的情況下,你應該嘗試使用input_single[i].value !== ""來代替。

+0

我看到我認爲,當我調用input_single就像是$('input')[0] .val因爲在上面的代碼我開始收集使用「curStep = $(this)」使用jquery操作符的elments,所以我雖然automatlly輸入被稱爲像jQuery元素。 – Mcloud