0

我试图让每个选项在框架中加载不同的页面

<!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";

但没有快乐。请帮忙。

4

1 回答 1

1

你可以这样做。

function selectCountry(){
 var mylist=document.getElementById("country");
 document.getElementById("frame").src=mylist.value+'.html';
}

或者

mylist.options[mylist.selectedIndex].value

value不见了。

于 2013-08-23T17:56:51.847 回答