JQuery 主页面调用子页面()中的JS方法,子页面调用主页面的JS方法</h1></div> </header><!-- .entry-header --> <div class="entry-content clear" ast-blocks-layout="true" itemprop="text" ><div class="htmledit_views" id="content_views"> <p><br/> </p> <p></p> <pre><code class="language-javascript"><!--主页面中的JS代码--> <script type="text/javascript"> //调用子页面的方法. var childWindow = $("#addFrame")[0].contentWindow; //表示获取了嵌入在iframe中的子页面的window对象。 []将JQuery对象转成DOM对象,用DOM对象的contentWindow获取子页面window对象。 childWindow.subFunction(); //调用子页面中的subFunction方法。 </script> <!--子页面中的JS代码--> <script type="text/javascript"> //子页面调用父页面中的方法。 window.parent.parentFunction(); //parentFunction是父页面中自定义的JS方法。 </script></code></pre> <br/> <br/> </div><hr class="wp-block-separator has-text-color has-ast-global-color-6-color has-alpha-channel-opacity has-ast-global-color-6-background-color has-background is-style-wide" style="margin-top:100px;"><div>版权声明:本文为houyanhua1原创文章,遵循<a href="http://creativecommons.org/licenses/by-sa/4.0/" rel="noopener nofollow" target="_blank"> CC 4.0 BY-SA </a>版权协议,转载请附上原文出处链接和本声明。</div><div>原文链接:<a href="https://blog.csdn.net/houyanhua1/article/details/79064351" target="_blank" rel="noopener nofollow">https://blog.csdn.net/houyanhua1/article/details/79064351</a></div></div><!-- .entry-content .clear --> </div> </article><!-- #post-## --> <nav class="navigation post-navigation" role="navigation" aria-label="Posts"> <span class="screen-reader-text">文章导航</span> <div class="nav-links"><div class="nav-previous"><a href="https://code84.com/843395.html" rel="prev"><span class="ast-left-arrow">←</span>vue2中的数据代理和数据劫持</a></div><div class="nav-next"><a href="https://code84.com/843397.html" rel="next">P问题,NP问题,NPC问题,以及三者之间的关系<span class="ast-right-arrow">→</span></a></div></div> </nav> </main><!-- #main --> </div><!-- #primary --> </div> <!-- ast-container --> </div><!-- #content --> <footer class="site-footer" id="colophon" itemtype="https://schema.org/WPFooter" itemscope="itemscope" itemid="#colophon"> <div class="site-below-footer-wrap ast-builder-grid-row-container site-footer-focus-item ast-builder-grid-row-full ast-builder-grid-row-tablet-full ast-builder-grid-row-mobile-full ast-footer-row-stack ast-footer-row-tablet-stack ast-footer-row-mobile-stack" data-section="section-below-footer-builder"> <div class="ast-builder-grid-row-container-inner"> <div class="ast-builder-footer-grid-columns site-below-footer-inner-wrap ast-builder-grid-row"> <div class="site-footer-below-section-1 site-footer-section site-footer-section-1"> <div class="ast-builder-layout-element ast-flex site-footer-focus-item ast-footer-copyright" data-section="section-footer-builder"> <div class="ast-footer-copyright"><p>Copyright © 2022 源码巴士 <a href="https://beian.miit.gov.cn/">鲁ICP备19024253号-1</a></p> </div> </div> </div> </div> </div> </div> </footer><!-- #colophon --> </div><!-- #page --> <script id='astra-theme-js-js-extra'> var astra = {"break_point":"921","isRtl":""}; </script> <script src='https://code84.com/wp-content/themes/astra/assets/js/minified/frontend.min.js?ver=3.8.5' id='astra-theme-js-js'></script> <script> /(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1); </script> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?c2326271c3004e261dee2dc30e62adf4"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>