gpt4 book ai didi

javascript - iframe 中的 jquery 搜索

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

我有类似以下代码:

<html>
<head>
</head>
<body>
<button id="test1" onclick="OnSave()">Save</button>
</body>
<script>
function OnSave() {
if ($("#test2").length)
{
alert("i see iframe");
}
else
{
//some code that will call Iframe via ajax
}
}
</script>
</html>

当我单击此按钮时,iframe 添加了:

<html>
<head>
</head>
<body>
<button id="test1" onclick="OnSave()">Save</button>
<iframe id="test2" src="smth">//button inside that will fire OnSave event</iframe>
</body>
<script>
function OnSave() {
if ($("#test2").length)
{
alert("i see iframe");
}
else
{
//some code that will call Iframe via ajax
}
}
</script>
</html>

所以,当我单击将从 iframe 调用 OnSave 函数的按钮时,jquery 没有看到我的 iframe 或其中的东西。我应该如何调用检查 iframe 是否存在?

最佳答案

您没有像那样调用 OnSave 函数..尝试这样做

<button id="test1" onclick="OnSave()">Save</button>

(注意函数名后面的括号)

编辑:好的,所以您可能想在调用函数之前返回父窗口

window.parent.functionName();

关于javascript - iframe 中的 jquery 搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34294527/

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