jQuery:按钮在 ajaxForm 返回的 html 中不起作用 - 如何重新绑定?
尝试让按钮在第二个表单中工作(jQuery UI chrome 和 jQuery 功能),该按钮位于第一个表单上调用的 ajaxForm 返回的 html 中。该按钮以第一种形式工作 - jQuery UI chrome 可见并且 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的按钮)
<button id="next_button" type="submit">Next</button>
非常感谢任何帮助!
Trying to get a button working (jQuery UI chrome and jQuery functionality) in a second form that is in the html returned by ajaxForm that has been called on a first form. The button works in the first form - the jQuery UI chrome is visible and the ajaxForm event works. For the second form, the button is generic and ajaxForm does not work, it submits to the target defined in the form not via jQuery. My problem I think involves bind() or delegate() or live() but I am just not understanding how to rebind. Here is my code:
// 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);
The Button:
jQuery('#next_button').button({
icons: { secondary: 'ui-icon-carat-1-e' }
});
The html(a form is returned by ajaxForm, this is the button using jQuery UI)
<button id="next_button" type="submit">Next</button>
Any help is much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这种方法使用了绑定。您应该使用 live:
$("#next_button").live('click', function() {
// 你的代码
});
I think this approach uses bind. You should use live:
$("#next_button").live('click', function() {
// your code
});
我向 document.ready 函数添加了一个名为 initBinding() 的函数,并在初始绑定时调用它:
I added a function called initBinding() to the document.ready function and called it at the initial bind: