【发布时间】:2016-01-27 16:44:28
【问题描述】:
我有两种不同的表单,在使用#orchestrationForm 提交表单时,我想查看#blah 表单中的filePaths 文本框是否为空。如何在 jquery 中做到这一点?
我的HTML和jquery如下:
<form id="blah"></form>
<form method="POST" action="/api/wand" enctype="multipart/form-data" id="orchestrationForm">
<section id="data-files">
<input type="text" class="form-control" name="filePaths" form="blah" />
</section>
</form>
$("#orchestrationForm").on("submit", function() {
var noFiles = false;
$("[name='filePaths']", this).each(function() {
if (!$(this).val()) {
noFiles = true;
}
});
if (noFiles) {
alert("Upload atleast one file");
}
return false;
});
在提交我的编排表单时,我正在按名称属性搜索 filePaths,如果它们为空,则会显示一个警告框。问题是,即使filePaths 文本框不为空,noFiles 的计算结果仍为 true,并显示警告框。我的 jquery 有什么问题?
【问题讨论】:
-
noFiles仅保留最后检查的文件输入字段的值。您在每次迭代时都覆盖它。