[英]Using Javascript to load an html page inside an iframe
I am trying to get each option to load a different page in frame 我正在尝试获取每个选项以在框架中加载不同的页面
<!DOCTYPE html>
<html>
<head>
<script>
function selectCountry()
{
var mylist=document.getElementById("country");
document.getElementById("frame").src=mylist.options[mylist.selectedIndex].html;
}
</script>
</head>
<form action="">
<select id = "country" onchange="selectCountry()">
<option value="america">America</option>
<option value="austria">Austria</option>
<option value="belgium">Belgium</option>
<option value="bosnia">Bosnia and Herzegovina</option>
<option value="croatia">Croatia</option>
<option value="estonia">Estonia</option>
<option value="france">France</option>
<option value="germany">Germany</option>
<option value="greece">Greece</option>
<option value="hungary">Hungary</option>
<option value="italy">Italy</option>
<option value="netherlands">Netherlands</option>
<option value="russia">Russia</option>
<option value="serbia">Serbia</option>
<option value="sweden">Sweden</option>
<option value="switzerland">Switzerland</option>
<option value="uk">UK</option>
</select>
</form>
<iframe id = "frame"></iframe>
</body>
</html>
but the page does not load in the iframe, apache gives an object not found message despite the page being in the same folder as index.html above. 但该页面未加载到iframe中,尽管该页面与上述index.html位于同一文件夹中,但apache仍显示一条未找到对象的消息。 I have tried changing the line:
我试过更改行:
document.getElementById("frame").src=mylist.options[mylist.selectedIndex].html;
to: 至:
document.getElementById("frame").src=mylist.options[mylist.selectedIndex] + ".html";
but no joy. 但没有喜悦。 plz help.
请帮助。
You can do it this way. 您可以这样进行。
function selectCountry(){
var mylist=document.getElementById("country");
document.getElementById("frame").src=mylist.value+'.html';
}
or 要么
mylist.options[mylist.selectedIndex].value
value
is missing. value
缺失。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.