简体   繁体   English

在iframe / Javascript中更改src

[英]Change src in iframe /Javascript

I have a problem 我有个问题

I do not know much of Javascript, just the basics. 我不太了解Javascript,只是基本知识。 I have this code. 我有这个代码。 But when you select an option from the list, DO NOT change the address "src" of the iframe. 但是,当您从列表中选择一个选项时,请勿更改iframe的地址“ src”。

Why is that? 这是为什么?

This code Javascript 此代码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]; 

}

This html 这个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>

This demo: http://jsfiddle.net/VzJNt/1/ 该演示: http : //jsfiddle.net/VzJNt/1/

I would suggest you use: 我建议您使用:

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

as this is the cross browser way of getting a DOM reference to an item with an id. 因为这是获取具有ID的商品的DOM引用的跨浏览器方式。

You should also check the browser's error console and see what javascript errors are reported on your page when it loads and/or when you change the select. 您还应该检查浏览器的错误控制台,并在加载和/或更改选择内容时查看页面上报告了哪些JavaScript错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM