我想告诉我的错误,如果“fileToUpload”为空(用JS显示错误),并停止刷新页面,如果“fileToUpload”为空PHP停止形态刷新显示错误的js
<form method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input class='new_post' type="submit" value="Upload Image" name="submit">
</form>
$('.new_post').click(function() {
var get_photo = $('#fileToUpload').get(0).files.length;
// If 0 file show error
if (get_photo == 0) {
openandclose('.error_box' , 'emptyyyy.', 1700);
$('.error_box').focus();
return false;
}
});
那么,你的问题是什么?测试它是否有效。我建议你在表单上使用提交事件,而不是点击按钮。但是,如果你想让我们更好地帮助你,请发布一个jsfiddle。 – Loenix
所以,可能get_photo == 0是错误的。我们无法测试 – Loenix
您可以指定问题吗? bcoz我在代码运行器中运行了你的代码,并且工作正常,所以我删除了我的答案。我正在取消您的参考。请指明您的问题。 – Iceman