2010-07-29 65 views
2

我正在使用具有“onComplete”选项的模态插件(colorbox)。我可以做以下实现我要去的效应部分(这仅仅是“onComplete”选项):jquery - 递归附加“提交”处理程序与表单与Ajax?

onComplete: function(){ 
$('.ajaxform').ajaxForm({ 
      success: function(responseText){ 
       $.colorbox({html:responseText}); 
      } 
     }); 
} 

的原因是,通过Ajax加载的模式中包含一种形式。该表格使用ajaxForm()提交,模式更改为反映responseText。它很好(对于第一种形式)。但问题是我连续有几种形式。附加'ajaxForm()'并仍然使用$.colorbox({html:responseText})以多种形式的好方法是什么?我想为未指定数量的表单(换句话说,在代码中我不能写它认为我有4种形式,因为也许我会稍后有5或3或什么的)

回答

0

只需将您的“onComplete”定义为独立功能即可:

function completeHandler() { 
    $('.ajaxform').ajaxForm({ 
    success: function(responseText) { 
     $.colorbox({html: responseText, onComplete: completeHandler}); 
    } 
    }); 
}