2015-11-18 55 views
0

我遇到了下面的腳本有問題。我覺得我錯過了一個支架關閉的地方,但無法找到它。我添加這個腳本的按鈕也不起作用,除非頁面被刷新。jquery腳本不加載,除非刷新頁面

$('.upload-new-essays').on('click', function() { 

    if (allInfo === true) { 

    $('.essays-new-table-row').each(function(index){ 
     firstName = $(this).find("#essays__student_first_name").val(); 
     lastName = $(this).find("#essays__student_last_name").val(); 
     // essayPackage = $(this).find("#essays__student_last_name").val() 
     documentUpload = $(this).find("#essays__document").val(); 
     if (((firstName != "") && (lastName === "" || documentUpload === "")) || ((lastName != "") && (firstName === "" || documentUpload === "")) || ((documentUpload != "") && (lastName === "" || firstName === ""))) 
     { 
      allInfo = false; 
     } 
     }) // essays-new-table-row 

    else if(allInfo === false) { 
     event.preventDefault(); 
     alert("You're missing information about one of your essays"); 
    } //else if 
    else { 
     event.stopPropagation(); 
    }; 
    }; // allInfo === true 
} // upload-new-essay 

回答

0

確實有一些語法錯誤。在我做出改變的方括號內看到我的評論。

$('.upload-new-essays').on('click', function() { 

    if (allInfo === true) { 

     $('.essays-new-table-row').each(function (index) { 
      firstName = $(this).find("#essays__student_first_name").val(); 
      lastName = $(this).find("#essays__student_last_name").val(); 
      // essayPackage = $(this).find("#essays__student_last_name").val() 
      documentUpload = $(this).find("#essays__document").val(); 
      if (((firstName != "") && (lastName === "" || documentUpload === "")) || ((lastName != "") && (firstName === "" || documentUpload === "")) || ((documentUpload != "") && (lastName === "" || firstName === ""))) { 
       allInfo = false; 
      } 
     }) // essays-new-table-row 
    } // [added bracket] 
    else if (allInfo === false) { 
     event.preventDefault(); 
     alert("You're missing information about one of your essays"); 
    } //else if 
    else { 
     event.stopPropagation(); 
    }; 
}); // allInfo === true [added ")"] 
// upload-new-essay [removed this bracket]