【问题标题】:jquery script not loading unless refresh page除非刷新页面,否则不会加载 jquery 脚本
【发布时间】:2015-11-18 02:36:28
【问题描述】:

我在使用以下脚本时遇到问题。我觉得我在某处附近缺少一个支架,但找不到它。除非刷新页面,否则我添加此脚本的按钮也不起作用。

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

【问题讨论】:

    标签: jquery refresh


    【解决方案1】:

    您确实有一些语法错误。请在下面的方括号中查看我进行更改的 cmets。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-16
      • 1970-01-01
      • 2012-11-12
      • 2012-05-21
      • 1970-01-01
      • 2022-07-19
      • 2012-07-31
      • 1970-01-01
      相关资源
      最近更新 更多