我有一个函数在iFrame中调用另一个函数,如下所示:
function globalFunc(value) {
//select and add ID to the iFrame
const preloading_iFrame = $("iframe[src*='http://127.0.0.1:8887/Components/preloading/index.html']");
preloading_iFrame.attr("id","preloadingID");
// call iframe's function
document.getElementById('preloadingID').contentWindow.iframeFunc(value);
}因为我想多次执行globalFunc,所以我想知道我们是否可以在第一次添加id之后跳过将它添加到iframe中。
类似于检查iframe是否有preloadingID作为id,然后不要再添加它!
有什么解决方案吗?
发布于 2020-04-02 04:59:22
不需要添加ID。您已经有了对元素的引用,只需使用它即可。
function globalFunc(value) {
//select and add ID to the iFrame
const preloading_iFrame = $("iframe[src*='http://127.0.0.1:8887/Components/preloading/index.html']");
// call iframe's function
preloading_iFrame[0].contentWindow.iframeFunc(value);
}索引jQuery集合将返回相应的DOM元素。
https://stackoverflow.com/questions/60979795
复制相似问题