jQuery iframe 隐藏/显示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10774775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 09:43:39  来源:igfitidea点击:

jQuery iframe hide/show

jqueryiframehideshow

提问by Mac Luc

Well im coding a site, and now stuck at the jQuery part, which aint my strongest thing. The site contains a top-menu nav-bar:

嗯,我正在编写一个网站,现在停留在 jQuery 部分,这不是我最擅长的事情。该站点包含一个顶部菜单导航栏:

<a href="aboutus.html" target="iframe"><img class="tab1" src="#.png"></a>
<a href="menu.html" target="iframe"><img class="tab2" src="#.png"></a>
<a href="gallery.html" target="iframe"><img class="tab3" src="#.png"></a>
<a href="shop.html" target="iframe"><img class="tab5" src="#.png"></a>
<a href="links.html" target="iframe"><img class="tab6" src="#.png"></a>
<a href="contact.html" target="iframe"><img class="tab7" src="#.png"></a>
</div>

And a iframe in the middle of the page, which loads the new html on nav click. When the index page loads, the iframe should not be seen before nav click. So ive got: iframe {display:none;} in css.

页面中间有一个 iframe,它在导航点击时加载新的 html。当索引页面加载时,在导航点击之前不应该看到 iframe。所以我得到了: iframe {display:none;} 在 css 中。

So, i need help with jQuery coding to show the iframe on nav click. Also with an effect to make the iframe hide again.

因此,我需要有关 jQuery 编码的帮助以在导航点击时显示 iframe。还具有使 iframe 再次隐藏的效果。

All the best.

祝一切顺利。

回答by SAK

Assuming that the <iframe>has an idof contentIframeyou could do the following:

假设<iframe>有一个idcontentIframe,你可以做到以下几点:

Show the <iframe>:

显示<iframe>

$("#contentIframe").show();

Hide the <iframe>:

隐藏<iframe>

$("#contentIframe").hide();

回答by Aymen Taarit

I think if you try to use a div and use the .load() method it will be better than the use of an iframe

我认为如果您尝试使用 div 并使用 .load() 方法,它会比使用 iframe 更好

$("a").click(function(){
$("#mydiv").load($(this).attr("href"));
});

回答by TrungDQ

The jQuery toggle methodwould be helpful.

jQuery的切换方法将是有益的。