使用按钮隐藏/显示iframe [英] Hide/Show iframes with a button
问题描述
我有一个包含2个iframe的网页,其中1个。我想在用户首次点击网页时隐藏iframe。将有2个按钮,每个iframe上方1个,用户必须点击按钮显示iframe。我也想要它,所以如果iframebutton1被按下,然后iframe2将被隐藏(如果它显示)和反之亦然。
I have a webpage with 2 iframes, 1 underneath the other. I would like both iframes hidden when a user first clicks on the webpage. There will be 2 buttons, 1 above each iframe and the user must click on the button to show the iframe. Also I want it so if iframebutton1 is pressed then iframe2 will be hidden (if it's showing) and visa versa.
这是我的代码:
jsfiddle.net/darego/Z62P7 /
jsfiddle.net/darego/Z62P7/
推荐答案
这里是我推荐使用的代码:
Here is the code that I would recommend using:
function hideToggle(button, elem) {
$(button).toggle( function () {
$(elem).hide();
},function () {
$(elem).show();
});
}
hideToggle(".button1", ".iframe1");
hideToggle(".button2", ".iframe2");
这是更新的工作小提琴: http://jsfiddle.net/Z62P7/1/
Here is the updated working fiddle: http://jsfiddle.net/Z62P7/1/
这只是使用一个简单的隐藏/显示功能所以你可以重复使用它。
This just uses a simple hide/show function so you can reuse it again and again.
这篇关于使用按钮隐藏/显示iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!