gpt4 book ai didi

ajax 加载内容后,jQuery 提交未捕获提交事件

转载 作者:行者123 更新时间:2023-12-01 03:29:08 25 4
gpt4 key购买 nike

我使用 jQuery Ajax 加载函数将内容加载到弹出窗口,并在加载函数回调函数中使用提交函数,但由于某种原因,事件根本没有触发。 (我使用 jQuery jquery-1.3.2.min.js)

$('.popup-container').load(url, function(){ 
/** Do some stuff here */
$("form").submit(function() {
alert("Form submitted!");
return false;
});
});

最佳答案

更新

从 jQuery 1.7 开始,.live()方法is deprecated 。它将在 jQuery 1.9 中被删除。使用.on()附加事件处理程序。旧版本 jQuery 的用户应使用 .delegate()优先于 .live()

<小时/>

原始答案

您可以使用 jQuery 方法 live() 来修复此问题。 jQuery 1.4 中已添加将 live()submit() 结合使用,因此您应该获得更新。 Here is a video tutorial on using live() with submit()

使用 live 函数时,您的代码应如下所示:

$("form").live('submit' , function() { 
alert("Form submitted!");
return false;
});

$('.popup-container').load(url);

关于ajax 加载内容后,jQuery 提交未捕获提交事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2100085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com