【发布时间】:2014-06-09 16:42:57
【问题描述】:
我有以下代码。
<div class="form-group">
<label for="store_account_name">Store Title</label>
<input type="text" value="" class="form-control" name="store_account_name" id="store_account_name" placeholder="Please insert store title of the external store" required />
</div>
<div class="form-group">
<label for="store_url">Store URL</label>
<input type="url" value="" class="form-control" name="store_url" id="store_url" placeholder="Please insert store URL as described in help section" required />
</div>
在提交按钮上,我想检查表单是否经过验证。我有一个具有 preventDefault 按钮的侦听器事件。因此,我只想在成功验证这两个输入时才发送 ajax 调用。是否有任何 JS 函数来检查验证状态或任何 css 属性添加到无效字段。
【问题讨论】:
-
现在提交表单时,即使未验证字段,也会进行 ajax 调用。只有在成功验证字段时才应进行 Ajax 调用。
-
请更改标题。你需要这样的东西:'在提交表单时添加事件监听器'。您绝对不需要检查表单是否已提交。
标签: javascript jquery ajax html forms