【问题标题】:My HTML dropdown won't work in IE6我的 HTML 下拉菜单在 IE6 中不起作用
【发布时间】:2011-07-25 10:51:52
【问题描述】:

所以我使用了一个带有国家列表的 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 中不行。任何帮助将不胜感激!

更新:所以我尝试了下面的前两种方法,替代弹出功能在任一浏览器中都不起作用,替换 document.getElementById 行没有改变任何东西,在 Firefox 中仍然可以正常工作, 不在 IE 中。

【问题讨论】:

    标签: javascript html internet-explorer-6


    【解决方案1】:
    document.getElementById("countrylist").value;
    

    需要:

    document.getElementById("countrylist")[document.getElementById("countrylist").selectedIndex].value;
    

    【讨论】:

    • 好电话! .
    【解决方案2】:

    这是我修复它的方法:

    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。

    谢谢你的帮助!

    【讨论】:

      【解决方案3】:

      您遇到的问题是获取国家/地区名称。我会将您的弹出功能更改为:

      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");
      
      }
      

      【讨论】:

        猜你喜欢
        • 2010-11-21
        • 1970-01-01
        • 2012-01-16
        • 1970-01-01
        • 2011-02-19
        • 1970-01-01
        • 2022-01-24
        • 2021-07-31
        • 1970-01-01
        相关资源
        最近更新 更多