我们有一个JavaScript中的表单绑定功能,例如

var formBind = function( event ) {
    event.preventDefault();
    var form = $(this);
    // some ajax post and validation portion here
    return false;
};


formBind在许多页面上都用作$('form:visible').submit(formBind);

现在,我要求在提交之前仅在特定页面上应用其他确认框。如何在最小的原始代码更改下添加该功能?

最佳答案

将原始表格套入新功能

var formBind = function( event ) {
    event.preventDefault();
    var form = $(this);
    // some ajax post and validation portion here
    return false;
};

var additionalFormBind = function( event ) {
    var result = null;
    // do additional work before original formBind
    result = formBind( event );
    // do additional work after original formBind
    return result;
}

$('form:visible').submit(additionalFormBind);

10-06 00:26