[英]Change src in iframe /Javascript
我有個問題
我不太了解Javascript,只是基本知識。 我有這個代碼。 但是,當您從列表中選擇一個選項時,請勿更改iframe的地址“ src”。
這是為什么?
此代碼Javascript
lstLinks = new Array(
"//e.issuu.com/embed.html#0/5202806",
"//e.issuu.com/embed.html#0/5203170",
"//e.issuu.com/embed.html#0/5203091",
"//e.issuu.com/embed.html#0/5203144"
);
function changeTest ()
{
var Index = document.menuForm.select1.options[document.menuForm.select1.selectedIndex].value;
document.testStar.src = lstLinks[Index];
}
這個HTML
<form action="../action/return.html" method="post" id="menuForm" name="menuForm" enctype="application/x-www-form-urlencoded">
<select id="select1" onchange="changeTest()" name="select1">
<option value="0" selected="selected">Escoger</option>
<option value="1">Diapositiva 1</option>
<option value="2">Diapositiva 2</option>
<option value="3">Diapositiva 3</option>
</select>
</form>
<iframe id="testStar" name="testStar" width="170" height="205" src="//e.issuu.com/embed.html#0/5203197" frameborder="0" allowfullscreen></iframe>
該演示: http : //jsfiddle.net/VzJNt/1/
我建議您使用:
document.getElementById("testStar").src = lstLinks[Index];
因為這是獲取具有ID的商品的DOM引用的跨瀏覽器方式。
您還應該檢查瀏覽器的錯誤控制台,並在加載和/或更改選擇內容時查看頁面上報告了哪些JavaScript錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.