2013-10-13 128 views
0

我遇到问题在iframe/Javascript中更改src

我不太了解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]; 

} 

这个网站

<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/

回答

0

我会建议你使用:

document.getElementById("testStar").src = lstLinks[Index]; 

,因为这是通过浏览器方式获取带有ID的项目的DOM引用。

您还应该检查浏览器的错误控制台,并查看加载时和/或更改选择时在页面上报告的JavaScript错误。