如果输入值为空,则下面的ajax代码将停止表单pprocess,然后显示弹出警报。问题是,警报弹出窗口关闭后,该过程将继续。如何在输入值不为空之前停止该过程?
$("#spdf-form").on('submit', function () {
var title = $('#spdf-form input[name="title"]').val();
var url = $('#spdf-form input[name="pdf"]').val();
if (title == "" || url == "") {
alert('Error; title or url is missing.');
return false;
}
});
答案 0 :(得分:1)
$("#spdf-form").on('submit', function (e) {
var title = $('#spdf-form input[name="title"]').val();
var url = $('#spdf-form input[name="pdf"]').val();
if (title == "" || url == "") {
alert('Error; title or url is missing.');
e.preventDefault();
return false;
}
});