html - 使用按钮显示和隐藏带有 iframe 的特定 div
问题描述
我只是想为家人做网站。我已经完成了带有 css 的基本 html,但是有一个问题。我需要实现页面更改 iframe,它链接到 php 中的两种表单。现在我已经找到了更改 href 的代码,但是这些 iframe 具有不同的高度,所以我想将它们都关闭到 div 中并用按钮显示第一个或第二个。
这是到目前为止的代码:
<section id="predplatne" class="clearfix">
<div class="predplatne_in">
<h2>Text</h2>
<div class="vyber">
<button class="button"><a href="http://www.php" target="frame">1</a></button>
<button class="button"><a href="http://www.php2" target="frame">2</a></button>
</div>
<div class="box">
<div class="in">
<iframe allowfullscreen frameborder="0" height="1700" id="frame" name="frame" src="http://www.php" width="480"></iframe> <a href="http://www.php" target="frame"></a> <a href="http://www.php2" target="frame"></a>
</div>
</div>
</div>
</div>
解决方案
您可以通过以下一些方法来实现
#if1, #if2{
display:none;
}
#btn1:active ~ div #if1, #btn2:active ~ div #if2{
display:block;
}
#rd1:checked ~ div #if1, #rd2:checked ~ div #if2{
display:block;
}
#cb1:checked ~ div #if1, #cb2:checked ~ div #if2{
display:block;
}
<!-- Reveal with active button -->
<button id="btn1">Reveal Frame 1</button>
<button id="btn2">Reveal Frame 2</button>
<br>
<!-- Reveal with checked radio -->
<input type="radio" id="rd1" name="reveal">
<label for="rd1">Reveal Frame 1</label>
<input type="radio" id="rd2" name="reveal">
<label for="rd2">Reveal Frame 2</label>
<br>
<!-- Reveal with checked checkbox -->
<input type="checkbox" id="cb1">
<label for="cb1">Reveal Frame 1</label>
<input type="checkbox" id="cb2">
<label for="cb2">Reveal Frame 2</label>
<div>
<iframe width="100px" id="if1" src="http://google.com">Test</iframe>
<iframe width="200px" id="if2" src="http://amazon.com">Test</iframe>
</div>
最简单的方法是使用 javascript 而不仅仅是 html 和 css
希望能帮助到你
推荐阅读
- javascript - MongoDB匹配文档,其中嵌入文档(对象数组)具有(嵌套)数组字段仅出现一次值
- ssl - 为什么使用中间 CA 时 SSL 连接失败?
- java - 为什么要尝试在包含布局的元素上设置 onClickListener 并抛出 NullPointerException?
- javascript - 将本地 JSON 加载到电子中,不能使用 require/include
- javascript - 在 Django 中使用 AJAX 进行分页
- plugins - pytest-appium:无法开始测试,被跳过
- veins - 在静脉 5.0 中,不再有 BaseWaveApplayer 类了吗?
- amazon-web-services - AWS boto3:模拟给定权限 json 策略文件的 IAM 角色
- jquery - 使用隐藏/显示 jQuery 和 innerWidth 用于特定屏幕尺寸,以在单击锚链接时隐藏移动菜单
- react-native - 如何使用 react-native-chart-kit 更改条形图中条形的背景颜色