[英]Pasleyjs Change default behavior of button in parsley form validation
I am using parsleyjs for form validation.我正在使用 parsleyjs 进行表单验证。 I have two buttons 'save' and 'cancel'.
我有两个按钮“保存”和“取消”。 I want to use save button for submitting the form, and for cancel button I do not want to submit form.
我想使用保存按钮提交表单,而对于取消按钮,我不想提交表单。 Currently when I click any of them, they take me to form submission
目前,当我单击其中任何一个时,他们会带我进行表单提交
<form id="form_validation">
<div>
<input type="text" required/>
</div>
<div>
<button type="submit">Save</button>
<button type="submit">Cancel</button>
</div>
</form>
<script>
var $formValidate = $('#form_validation');
$formValidate.parsley().on('form:submit', function () {
//this code is called when I click save or cancel button
});
</script>
If you 'cancel' button isn't to submit the form, then it shouldn't have a type="submit"
.如果您的“取消”按钮不是为了提交表单,那么它就不应该有
type="submit"
。 Problem solved.问题解决了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.