[英]Using Javascript to load an html page inside an iframe
我正在嘗試獲取每個選項以在框架中加載不同的頁面
<!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>
但該頁面未加載到iframe中,盡管該頁面與上述index.html位於同一文件夾中,但apache仍顯示一條未找到對象的消息。 我試過更改行:
document.getElementById("frame").src=mylist.options[mylist.selectedIndex].html;
至:
document.getElementById("frame").src=mylist.options[mylist.selectedIndex] + ".html";
但沒有喜悅。 請幫助。
您可以這樣進行。
function selectCountry(){
var mylist=document.getElementById("country");
document.getElementById("frame").src=mylist.value+'.html';
}
要么
mylist.options[mylist.selectedIndex].value
value
缺失。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.