因此,我使用一个HTML选择框和一个国家列表以及一个按钮来打开一个小窗口,其中包含HTML选择框中所选项目的更多细节。
我是这样做的(我对这里的任何愚蠢行为表示歉意,我对Javascript还是很陌生的):
//in header
<script type="text/javascript">
function popUp()
{
countryName = document.getElementById("countrylist").value;
document.write(countryName);
dest = "countries/" + countryName + ".html";
window.open(dest, 0, "toolbar=0, scrollbars=0, statusbar=0, menubar=0,resizable=0,width=400,height=400,left=440,top=312");
}
</script>
<form id="countryform">
<select id="countrylist">
<!--List of countries removed for brevity-->
</select>
<input type="button" name="countryBtn" value="Submit Query" onClick="popUp();">
</form>
这在Firefox中很好,但在IE6中就不行了。任何帮助都将不胜感激!
最新情况:因此,我尝试了下面的三种方法,替代弹出函数在这两种浏览器中都无法工作,并替换了文档。getElementById行没有改变任何事情,在Firefox中仍然很好,在IE中没有。
发布于 2017-12-27 08:03:37
document.getElementById("countrylist").value;
需要:
document.getElementById("countrylist")[document.getElementById("countrylist").selectedIndex].value;
发布于 2017-12-27 08:17:39
我就是这样修好的:
function popUp()
{
var c = document.getElementById("countrylist");
var countryName = c.options[c.selectedIndex].text;
var dest = "countries/" + countryName + ".html";
window.open(dest, 0, "toolbar=0, scrollbars=0, statusbar=0, menubar=0,resizable=0,width=400,height=400,left=440,top=312");
}
这在IE6和FF3中都是有效的。
无论如何,谢谢帮助!
发布于 2017-12-27 09:46:58
你遇到的问题是国名的获得。我会将您的弹出功能更改为:
function popUp() {
var e = document.getElementById("countrylist");
var countryName = e.options[e.selectedIndex].value;
dest = "countries/" + countryName + ".html";
window.open(dest, 0, "toolbar=0, scrollbars=0, statusbar=0, menubar=0,resizable=0,width=400,height=400,left=440,top=312");
}
https://stackoverflow.com/questions/-100000017
复制相似问题