jQuery:按钮在ajaxForm返回的html中不起作用-如何重新绑定?

jQuery:按钮在ajaxForm返回的html中不起作用-如何重新绑定?,jquery,button,ajaxform,dynamic-rebinding,Jquery,Button,Ajaxform,Dynamic Rebinding,试图让按钮在第二个表单中工作(jQuery UI chrome和jQuery功能),该表单是在第一个表单上调用的ajaxForm返回的html中。该按钮在第一种形式下工作——jQueryUIChrome可见,ajaxForm事件工作。对于第二个表单,按钮是通用的,ajaxForm不起作用,它提交给表单中定义的目标,而不是通过jQuery。我认为我的问题涉及bind()或delegate()或live(),但我不知道如何重新绑定。这是我的密码: // prepare Options Object

试图让按钮在第二个表单中工作(jQuery UI chrome和jQuery功能),该表单是在第一个表单上调用的ajaxForm返回的html中。该按钮在第一种形式下工作——jQueryUIChrome可见,ajaxForm事件工作。对于第二个表单,按钮是通用的,ajaxForm不起作用,它提交给表单中定义的目标,而不是通过jQuery。我认为我的问题涉及bind()或delegate()或live(),但我不知道如何重新绑定。这是我的密码:

// prepare Options Object for first form submit of new program
     var options = { 
     target:     '#add_program_container', 
     success:    function (response) {
              jQuery('#add_program_container').html(response);
        }
     }; 

     // pass options to ajaxForm for first form sumit of new program

     jQuery('#new_program_form').ajaxForm(options);

      // prepare Options Object for second form submit of new program - requirements
     var options = { 
      target:     '#add_program_container', 
      success:    function (response) {
         jQuery('#add_program_container').html(response);

         }
     }; 

     // pass options to ajaxForm for second form submit of new program - requirements

     jQuery('#new_program_form_two').ajaxForm(options);
按钮:

jQuery('#next_button').button({
      icons: { secondary: 'ui-icon-carat-1-e' }
     });
html(一个表单由ajaxForm返回,这是使用jQuery UI的按钮)

下一步

非常感谢您的帮助

我认为这种方法使用bind。您应该使用live:

$(“#下一步按钮”).live('单击',函数()){ //你的代码
});

我在document.ready函数中添加了一个名为initBinding()的函数,并在初始绑定时调用它:

jQuery(document).ready(function() {

initBinding();

//functions for initial bind

function initBinding() {

    //other functions to rebind after ajax success, can be same functions called initially
}
}
jQuery(document).ready(function() {

initBinding();

//functions for initial bind

function initBinding() {

    //other functions to rebind after ajax success, can be same functions called initially
}
}