gpt4 book ai didi

iFrame 中加载新页面时的 jQuery 事件

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

我正在尝试在父级上设置一个事件,当 iframe 加载新页面时(可能是通过用户单击链接),该事件会被触发。

HTML:

<iframe name="posts" id="posts" src="edit.php">

JS:

$(document).ready(function() {
$('iframe#posts').live('load', function() {
console.log('live');
});
});

问题是 console.log() 语句永远不会被触发。我怎样才能实现我想要做的事情?

最佳答案

解决问题的最简单方法是使用 jQuery 创建 iframe。

$(document).ready(function() {
$("<iframe />").attr({
id: "posts",
src: "edit.php"
}).load(function() {
console.log('live');
}).appendTo("body");

此问题已asked here before .

关于iFrame 中加载新页面时的 jQuery 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4452773/

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