我想要一个按钮来打开 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/