2016-09-27 82 views
-3
<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出現

+0

的set.attribute部分犯規任何意義。我想你認爲x.setAttribute(「src」,「http://www.miamigov.com/home/」);並沒有「LOADHERE」ID。它可能是「loadiframehere」 – TheWandererr

+0

你沒有做任何事情來隱藏它。當它已經可見時,無法顯示某些東西 – charlietfl

+0

我修正了這個問題,但仍然無法正常工作。但是,謝謝。 – Leslievramirez

回答

0

這是修復程序。你的代碼是完全錯誤的。你必須知道Javascript是區分大小寫的。 getElementByID與getElementById不同。

此外,您創建了一個「x」元素作爲iframe,但是您也在html中創建了一個iframe,並且「set」屬性未附加到任何元素。你創建了一個名爲「myFunction」的函數,但在你稱之爲「myfunction」的按鈕上。再次,JavaScript是區分大小寫

你應該學習Javascript語法。

function myfunction(){ 
 
var x = document.createElement("IFRAME"); 
 
x.setAttribute("src","http://www.miamigov.com/home/"); 
 
x.setAttribute("width","600"); 
 
x.setAttribute("height","400"); 
 

 
document.getElementById("loadiframehere").appendChild(x); 
 

 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<center> 
 
<button type= "button" onclick="myfunction()">Things To Do in Miami</button> 
 
<div id="loadiframehere"> 
 

 
</div> 
 
</center>

+0

謝謝soo !!有效!我一直在試圖找出這樣的3天!並感謝您的建議。你剛剛保存了我的及格成績! – Leslievramirez

+0

沒問題,只是不斷學習 – Stormhashe

+0

我會的,謝謝! – Leslievramirez

相關問題