jQuery Validate-class ="cancel"提交按钮仅停止一次验证 [英] JQuery Validate - class="cancel" submit button only stops validation once

查看:195
本文介绍了jQuery Validate-class ="cancel"提交按钮仅停止一次验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有按钮的表单,我没有提交表单的内容,但是(有必要)它们是提交按钮. 我为他们提供了取消"类,并且在他们第一次点击时就取消了提交.理想的效果.但是,随后的所有点击都会恢复正常;提交表格.我不想要的.

I have a form with buttons I do not what to Submit the form, but they are (necessarily) submit buttons. I've given them the class "cancel" and on the first click they are cancelling submission. the desired effect. However, any subsequent click is then back to normal; Submitting the form. Which I don't want.

现在,单击这些按钮确实发生了一些回发.我尝试运行$('form').validate({...});而不是document.ready在pageLoad上起作用,但这完全停止了验证工作.

Now, I do have some post-backs happening on click of these buttons. I tried running the $('form').validate({...}); function on pageLoad instead of document.ready, but this just stopped the validation working at all.

其中一个按钮的HTML是:

the HTML for one of the buttons is:

<input type="submit" class="btncat_deselected cancel" 
id="Pet3btncat" value="" name="Pet3btncat" />

任何想法将是最有帮助的.谢谢.

Any Ideas would be most helpful. Thanks.

推荐答案

好,请使用DA评论的内容;最后,我告诉表单在提交时不对其进行验证(onSubmit:false,),然后创建了一个函数来隐藏实际的提交按钮,并具有一个图像(或者可能是普通按钮)以在验证为true时提交表单:

Ok, using what DA commented; I ended up telling the form to NOT validate on submit ( onSubmit: false, ) and then created a function to hide the actual submit button, and have an image (or could of been a normal button) to submit the form on validation being true:

$(function() {

        $('#Petform #btnNext').hide();
        $('#Petform #NextWrapper').append('<img src="../images/next.gif" alt="submit this form" style="cursor:pointer;" />')
        $('#Petform #NextWrapper img').live('click', function() { 
                  if( $('form').valid() ) {
                        $('#btnNext').click();
                  } 
            });

      });

通过这种方式,如果表单无效,则不会将其发送到服务器;如果禁用了JS,则正常的表单按钮/功能也会恢复.

This way the form wont be sent to server if it isnt valid, and normal form buttons/functionality reverts if JS is disabled.

谢谢你们,伙计们.

这篇关于jQuery Validate-class ="cancel"提交按钮仅停止一次验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆