当前位置: 动力学知识库 > 问答 > 编程问答 >

jquery script not loading unless refresh page

问题描述:

I'm having trouble with the below script. I feel like i'm missing a bracket close somewhere but can't find it. The button i'm adding this script too doesn't work unless the page is refreshed.

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

网友答案:

You do indeed have a few syntax errors. See my comments below in square brackets where I made changes.

$('.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]
分享给朋友:
您可能感兴趣的文章:
随机阅读: