我遇到以下脚本的问题。我觉得我在某个地方错过了一个支架,却找不到它。除非刷新页面,否则我添加此脚本的按钮也不起作用。
$('.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 :(得分: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]