html - 打开隐形框架的按钮

标签 html css

我想要一个按钮来打开 iframe。我尝试过各种形式的 onclick,但我错过了将这两段代码放在一起的秘诀。

<button type="button">Test</button>
<iframe style="visibility:hidden;display:none" src="example.com"></iframe>

最佳答案

只需使用一个 id :)

试试下面的代码: 即使制作一个真正的 js 函数更好;)

这只是显示预加载的 iframe

<button type="button" onclick="var a = document.getElementById('myIframe');a.style.display='block'">Test</button>
<iframe id="myIframe" style="width:100px;height:100px;display:none" src="google.com"></iframe>

这会显示 iframe 并加载它:

<button type="button" onclick="var a = document.getElementById('myIframe');a.src='http://google.com';a.style.display='block'">Test</button>
<iframe id="myIframe" style="width:100px;height:100px;display:none" src=""></iframe>

关于html - 打开隐形框架的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32260988/

相关文章:

javascript - 每次 <h4> 到达窗口中间时运行一个函数来改变图像

asp.net - 在 iframe 中查找组件

HTML/CSS 两个看似相等的元素,位置不同

javascript - 我想在我的选择标签中显示选择性别作为占位符

javascript - 单击后退按钮时重定向到不同页面 "not working"

html - 如何将负半径添加到半圆?

html - 使 Span 类响应 + div 之间的间距

html - 多个背景图像位置

html - 防止 html 元素在分辨率太小时被挤压

html - Windows 8.1 上 Chrome 中的字体大小损坏