jquery验证删除submitHandler

时间:2009-07-02 15:50:20

标签: jquery jquery-validate

有没有办法在设置后删除submitHandler或invalidHandler?如果我提交我的表单并取消我的确认模式窗口,我的其他按钮将继承这些处理程序而不是他们想做的事情。

我尝试在各个地方取消绑定表单提交。除了尝试重新定义后退和保存按钮的验证,但它总是先调用submitHandler

<script type="text/javascript">


    $(document).ready(function() {


        $(window).keydown(function(event){

             document.getElementById('save').src = "/bttn-save.jpg";

        });


        $.validator.setDefaults({
             submitHandler: function() { 
                  tb_show("", "#TB_inline?height=400&width=600&inlineId=confirmblock", null);
             }
        });

        var errorimage = "<img src=\"error.png\" width=\"19\" height=\"19\" alt=\"error\" title=\"error\" style=\"vertical-align:top;margin-top:5px;\" />";

        $('#submit').click(function(e) {

            $('#promoForm').validate({
                submitHandler: function() { 
                  tb_show("", "#TB_inline?height=400&width=600&inlineId=confirmblock", null);
             },
                invalidHandler: function(e, validator) {
                 var errors = validator.numberOfInvalids();
         if (errors) {
              tb_show("", "#TB_inline?height=150&width=250&inlineId=errorblock", null);
         }  

        },
                errorElement: "span",
                rules: {
                    additionalinfo: "required"
                },
                messages: {
                    additionalinfo: errorimage
                } 

            });

            document.getElementById('td_info').innerHTML = document.getElementById('additionalinfo').value;

        });

        $('#back').click(function() {
            $("#promoForm").attr("action", "/step6/?action=back&email=%%=RequestParameter("email")=%%"); 
        });


        $('#save').click(function() {
            $("#promoForm").attr("action", "/step7/?action=save&email=%%=RequestParameter("email")=%%"); 
        });

        $('#confirm').click(function() {
            document.getElementById('promoForm').action = "http://pages.email.microsoftemail.com/thatsit/?email=%%=RequestParameter("email")=%%"
            document.getElementById('promoForm').submit(); 

        });

        $('#attach').click(function() {
            tb_show("", "#TB_inline?height=300&width=336&inlineId=uploadblock", null);
        });

    });
</script>

1 个答案:

答案 0 :(得分:0)

当它们存在模态时,我从表单中删除所有事件。当我点击我的提交按钮时,我重新添加了所有验证。这需要根据我的特定情况修改ThickBox和Validation JS。