jQuery:在 ajaxForm 提交返回 HTML 后重新绑定有效,但后续提交无效...为什么,一次重新绑定是有限制的?
你好,我有一个带有按钮和链接 jQuery 事件的表单。我正在使用 ajaxForm 提交表单,成功后它会返回另一个表单。第二种形式具有相同的按钮和链接 jQuery 事件,我使用在 document.ready() 函数开头调用的 init 函数重新绑定它们。重新绑定效果很好。当我使用 ajaxForm 提交第二个表单时,将返回第三个表单,并具有相同的按钮和链接事件。尽管使用第二个 init 函数,按钮和链接事件不会重新绑定,这就是问题所在。这是 jQuery 的限制 - 重新绑定两次吗?任何想法都非常感激。
代码:
//init functions
jQuery(document).ready(function() {
initBinding();
initBindingTwo();
//button
jQuery('#next_button').button({
icons: { secondary: 'ui-icon-carat-1-e' }
);
// pass options to ajaxForm for first form sumit of new program
jQuery('#new_program_form').ajaxForm(options);
//this one works after first form submit
function initBinding() {
jQuery('#next_button').button({
icons: { secondary: 'ui-icon-carat-1-e' }
});
//this one does not work after second form submit
function initBindingTwo() {
jQuery('#next_button').button({
icons: { secondary: 'ui-icon-carat-1-e' }
});
});
Hello I have a form with a button and link jQuery events. I am submitting the form using ajaxForm which returns another form on success. The second form has the same button and link jQuery events which I re-bind using an init function called at the beginning in the document.ready() function. The rebind works fine. When I submit the second form using ajaxForm, a third form is returned with the same button and link events. The button and link events do not re-bind though using the second init function, which is the problem. Is this a limitation to jQuery - rebinding twice? Any thoughts much appreciated.
Code:
//init functions
jQuery(document).ready(function() {
initBinding();
initBindingTwo();
//button
jQuery('#next_button').button({
icons: { secondary: 'ui-icon-carat-1-e' }
);
// pass options to ajaxForm for first form sumit of new program
jQuery('#new_program_form').ajaxForm(options);
//this one works after first form submit
function initBinding() {
jQuery('#next_button').button({
icons: { secondary: 'ui-icon-carat-1-e' }
});
//this one does not work after second form submit
function initBindingTwo() {
jQuery('#next_button').button({
icons: { secondary: 'ui-icon-carat-1-e' }
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终放弃了上述方法,坚持使用两次ajax调用,并且只提交两次表单,这解决了问题。
I ended up abandoning the above approach and stuck to two ajax calls, and only two form submits, which solved the problem.