<center>
<button type= "button" onclick="myFunction()">Things To Do in Miami</button>
<div id="loadiframehere">
<iframe id="myframe"src="https://thingstodo.expedia.com/miami-florida-activities/" width="450" height="275" > </iframe>
</div>
</button>
<script>
function myfunction(){
var x = document.createElement("IFRAME")
set.attribute("src","http://www.miamigov.com/home/");
set.attribute("width","600")
set.attribute("height","400")
document.getElementByID("myframe").src="http://www.miamigov.com/home/"
document.getElementByID("myframe").width="300";
document.getElementByID("LOADHERE").appendchild(x);
}
</script>
</center>
</section>
這是我的老師給我們複製的代碼,但是我做了,按鈕不起作用。在我點擊按鈕之前,iframe只出現在它旁邊。當你點擊一個按鈕時,你如何使iframe出現
的set.attribute部分犯規任何意義。我想你認爲x.setAttribute(「src」,「http://www.miamigov.com/home/」);並沒有「LOADHERE」ID。它可能是「loadiframehere」 – TheWandererr
你沒有做任何事情來隱藏它。當它已經可見時,無法顯示某些東西 – charlietfl
我修正了這個問題,但仍然無法正常工作。但是,謝謝。 – Leslievramirez