除非刷新页面,否则不加载jquery脚本

时间:2015-11-18 02:36:29

标签: jquery refresh

我遇到以下脚本的问题。我觉得我在某个地方错过了一个支架,却找不到它。除非刷新页面,否则我添加此脚本的按钮也不起作用。

$('.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

1 个答案:

答案 0 :(得分: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]