我有点击功能,我需要在里面添加另一个功能来做一个暂停和完成,然后恢复onclick功能继续。 -function to call和pause: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}");
});
});
请帮助我们如何获得,验证首先通过,然后在点击功能上运行payment_order ????
答案 0 :(得分:1)
也许最好在表单上捕获提交事件。 这样,如果用户按下表单字段上的回车键,您仍然可以捕获提交事件,如果验证失败,则使用event.preventDefault()将其拒绝
$( "#form_id" ).submit(function( event ) {
if(yourValidationFunction() === false){
event.preventDefault();
}
//else the submit will pe performed
});
仍可以使用该按钮
$('#payment_submit_order').click(function() {
$( "#form_id" ).submit();
});