取消按钮php表单jquery

取消按钮php表单jquery,php,javascript,jquery,forms,Php,Javascript,Jquery,Forms,以下是我表格上的按钮: <input type="submit" id="form-submit" class="btn" name="save" value="verzenden" /> <input type="submit" name="cancel" class="btn" value="annuleren" /> 但是在提交表单之前,我使用一些jQuery来验证表单,现在我不能单击cancel,因为它将首先验证 这是我的jQuery代码: <script

以下是我表格上的按钮:

<input type="submit" id="form-submit" class="btn" name="save" value="verzenden" />
<input type="submit" name="cancel" class="btn" value="annuleren" />
但是在提交表单之前,我使用一些jQuery来验证表单,现在我不能单击cancel,因为它将首先验证

这是我的jQuery代码:

<script type="text/javascript">

    $(document).ready(function(){ 
        $('#cancel').delegate('','click change',function(){
            console.log('test');
        });

        $('form').submit(function(){
            var proceed = true;

            $('.required').each(function(){
                if ($(this).val() == '' || $(this).val() == 0 || $(this).val() == '0') {
                    $(this).css('border-color', '#F00');
                    proceed = false;
                }
                else {
                    $(this).css('border-color', '#999');
                }
            });


            return proceed;
        });

        // Check on typing if a required field is empty
        $('.required').keyup(function(){
            if ($(this).val() == '' || $(this).val() == 0 || $(this).val() == '0' ) 
                $(this).css('border-color', '#F00');
            else 
                $(this).css('border-color', '#999');
        }); 
    });
</script>

$(文档).ready(函数(){
$('#取消')。委托('','单击更改',函数(){
console.log('test');
});
$('form')。提交(函数(){
var=true;
$('.required')。每个(函数(){
如果($(this.val()=''| |$(this.val()==0 | |$(this.val()='0')){
$(this.css('border-color','#F00');
继续=错误;
}
否则{
$(this.css('border-color','#999');
}
});
返回并继续;
});
//如果必填字段为空,请检查键入
$('.required').keyup(函数(){
如果($(this.val()=''| |$(this.val()==0 | |$(this.val()='0'))
$(this.css('border-color','#F00');
其他的
$(this.css('border-color','#999');
}); 
});
当我点击cancel时,如何忽略jQuery并重定向到page.php? 谢谢

当您的表单中没有id为cancel的元素时,这将不起作用

换那个按钮

<input type="submit" name="cancel" class="btn" value="annuleren" />


这就是我现在得到的:
谢谢你,老师

//javascript

$('#cancel').delegate('','click change',function(){
    window.location = "testimonials.php";
    return false;
});
//php

//html

<input name="cancel" type="submit" id="cancel" class="btn" value="annuleren" />


单击“取消”按钮时,为什么不直接使用JavaScript重定向到页面?提交表单只是为了丢弃表单并重定向,这是一种浪费带宽和时间的行为。请记住,客户端验证绝对不安全。谢谢,我会尝试javascript重定向,我还有php验证。这是可行的,但我仍然会看到验证(红色边框),在它重定向之前,如何使用类似php exit()的东西在javascript中?很抱歉,我错发了html:$
<input type="submit" id="cancel" name="cancel" class="btn" value="annuleren" />
$('#cancel').delegate('','click change',function(){
    window.location = "testimonials.php";
    return false;
});
if($_POST['cancel'])
{
    Helper::redirect('testimonials.php');
}
<input name="cancel" type="submit" id="cancel" class="btn" value="annuleren" />