Jquery使用链接验证并发送表单 [英] Jquery Validate and send form with a link
本文介绍了Jquery使用链接验证并发送表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
<script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="js/jquery.validate.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#alta").validate();
});
</script>
<form id="alta" method="post" action="<?= $this->Html->url('/'); ?>alta">
<label>Nombre:</label>
<input type="text" id="name" class="field required" name="data[name]">
</form>
<a href="#" onClick="alta.submit(); return false;" id="button" class="button">Send</a>
我的问题是我不使用提交输入,需要使用链接,但提交表单并且无效。
And my problem is I do not use submit input, need to use a link, but submits the form and not valid.
谢谢
推荐答案
没有提交按钮你需要检查表格是否有效。
Without a submit button you need to check the form is valid manually.
首先,从HTML中删除 onclick
属性 - 这不是附加事件的好方法。
Firstly, remove the onclick
attribute from your HTML - this is not a good method of attaching events.
<a href="#" id="button" class="button">Send</a>
然后将其放在你的jQuery代码中:
Then place this in your jQuery code:
$("#button").click(function() {
if ($("#alta").valid()) {
$("#alta").submit();
}
});
这篇关于Jquery使用链接验证并发送表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文