Javascript 如何包装函数和暂停

Javascript 如何包装函数和暂停,javascript,jquery,validation,Javascript,Jquery,Validation,我有一个on-click函数,我需要在其中添加另一个函数来暂停并完成,然后恢复onclick函数以继续。 -要调用和暂停的函数:errorCheckingOrder()。见下文 下面是函数onclick: $('#payment_submit_order').on('click', function(){ errorCheckingOrder();//here is the function calling it var

我有一个on-click函数,我需要在其中添加另一个函数来暂停并完成,然后恢复onclick函数以继续。 -要调用和暂停的函数:errorCheckingOrder()。见下文

下面是函数onclick:

        $('#payment_submit_order').on('click', function(){

                    errorCheckingOrder();//here is the function calling it

        var data = {fName : $("#returnfirstName").val(), lName: $("#returnlastName").val(), add1: $("#returnaddress1").val(), add2: $("#returnaddress2").val()};
        data.city = $("#returncity").val();
        data.state = $("#returnstate").val();
        data.mail = $("#returnemail").val();
        data.zipcode = $("#returnzipcode").val();
        var returnAddress = saveAddress(data);

        var value = $('input[name=shippingType]:checked').val();
        if(value == 0){
            var address = saveAddress();
            var shipping = ($('input[name=shippingmethod]:checked').val()*productCart.length).toFixed(2);
            for(var i in productCart) {
                productCart[i].addressId = address;
                productCart[i].shippingmethod = shipping;
                productCart[i].returnAddress = returnAddress;
            }
        }else{
            for(var i in productCart) {
                var address = $("#selectProductAddress_"+productCart[i].uProductID).val();
                productCart[i].addressId = address;
                productCart[i].returnAddress = returnAddress;
                var shipping = 0;
                $('input[name^="shippingmethod_"]').each(function(){
                    if($(this).is(":checked")){
                        shipping += parseFloat($(this).val());
                    }
                });
                shipping = shipping.toFixed(2);
                productCart[i].shippingmethod = shipping;
            }
        }
               });
下面是执行错误检查/验证的函数。我们需要先通过,然后再通过。继续。上面的函数

        //Personlize & Customize Validation placed here
        $(function errorCheckingOrder(){
            bindValidation("shipping_gift_card","${pageContext.response.locale}");
            $("#payment_submit_order").click(function(){
                return isValidation("shipping_gift_card","${pageContext.response.locale}");
            });
        }); 

请帮助我们如何获得,先通过验证,然后运行点击付款订单功能???

也许最好在表单上捕获提交事件。 这样,如果用户在表单字段上按enter键,您仍然可以捕获提交事件,并在验证失败时使用event.preventDefault()拒绝它

按钮仍然可以使用

$('#payment_submit_order').click(function() {
  $( "#form_id" ).submit();
});

最好使大型代码示例自包含并保存到。使人们更容易使用您的代码。为什么我们没有看到这一点,我们尝试了您的代码,并且它似乎是我们希望能够工作的路径$(“#form_id”).submit(函数(事件){if(yourValidationFunction()==false){event.preventDefault();}//否则将执行提交});谢谢,我们将在测试过程中进行更新。我们希望在提交时启动验证,一旦验证良好(或返回false),然后恢复提交功能。你能看看我们的思路,给我们一些直接的指导吗。真的很感激。。。。。。。。。。。。。。你回答了,但我们不明白。。。
$('#payment_submit_order').click(function() {
  $( "#form_id" ).submit();
});