2012-03-01 50 views
1

我将在失败的状态中提出我的问题。我花了近10个小时花费在这个单一的对不起的小问题上,并且花费了大量的时间在这里通过类似的问题在互联网上的stackoverflow和其他地方进行挖掘。我使用的是带有选项值的选择表单来完成页面的链接,但是当我使用onchange(或onblur)来获取所选元素时,IE7认为这里没有任何东西(尽管IE8,9 ,Chrome,FF功能如我所愿)。“getElementById(...)。options is null or not an object”in IE7 only

CMS很复杂,所以我可以添加脚本的地方有一些限制,但是我确实意识到DOM在这里可能会成为一个问题。我也试着把这个函数放在window.onload里面,以防造成问题,但那似乎不是。这里是我的代码:

<form name="myBrowseForm" action="/portal/" method="post"> 
    <label for="redirect">Choose a Region</label> 
    <br /> 
    <select id="organization" onchange="document.myBrowseForm.action=document.getElementById('organization').options[document.getElementById('organization').selectedIndex].value;" name="shortcut"> 
     <option value="#">Select a Region</option> 
     <option value="/r1">New England (1)</option> 
     <option value="/r2">Northeast & Caribbean (2)</option> 
     </select> 
     <input border="0" hspace="5" src="/btn_go.gif" alt="Go" onclick="if(document.myBrowseForm.action != ''){document.myBrowseForm.submit();} else return false;" type="image"> 
     </form> 

我很感谢您对我的任何指导!

+0

一个东西,旧版本IE的JavaScript引擎强制实施,但很多人的不都是独一无二的元素ID。你可以仔细检查你的元素ID在页面上是唯一的吗? – 2012-03-01 16:35:35

+0

可能的重复http://stackoverflow.com/questions/3147556/javascript-getelementbyid-is-null-or-not-an-object-ie和http://stackoverflow.com/questions/7839423/parent-document- getelementbyid-is-null-or-not-an-object-in-ie7 – Bot 2012-03-01 16:35:50

+0

<6%的智能程度不足以升级浏览器的用户可能不足以使用cms。我的2美分。 – 2012-03-01 16:37:22

回答

1

或许你可以尝试这样的事:

<form name="myBrowseForm" action="/portal/" method="post"> 
    <label for="redirect">Choose a Region</label> 
    <br /> 
    <select id="organization" onchange="document.myBrowseForm.action=this.options[this.selectedIndex].value;" name="shortcut"> 
     <option value="#">Select a Region</option> 
     <option value="/r1">New England (1)</option> 
     <option value="/r2">Northeast & Caribbean (2)</option> 
    </select> 
    <input border="0" hspace="5" src="/btn_go.gif" alt="Go" onclick="if(document.myBrowseForm.action != ''){document.myBrowseForm.submit();} else return false;" type="image"> 
</form> 
0

您是否试过document.getElementById('organization').value而非选项?

,并提供:

<form name="myBrowseForm" action="/portal/" method="post"> 
    <label for="redirect">Choose a Region</label> 
    <br /> 
    <select id="organization" onchange="document.myBrowseForm.action=document.getElementById('organization').value;" name="shortcut"> 
     <option value="#">Select a Region</option> 
     <option value="/r1">New England (1)</option> 
     <option value="/r2">Northeast & Caribbean (2)</option> 
    </select> 
    <input border="0" hspace="5" src="/btn_go.gif" alt="Go" onclick="if(document.myBrowseForm.action != ''){document.myBrowseForm.submit();} else return false;" type="image"> 
</form> 
相关问题