0

我有个问题

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

4

1 回答 1

0

我建议你使用:

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

因为这是获取对具有 id 的项目的 DOM 引用的跨浏览器方式。

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

于 2013-10-13T06:23:31.390 回答