getElementById在IE和FireFox浏览器中的区别

JS代码:

function GoToList()
{
    //var partID=document.getElementById('SelectClassId').selectedOptions[0].value;//此语句在IE中无法正常取值,但在非IE中正常
    //以下为通用方法:
    var a=document.getElementById("SelectClassId");//从document对象中,获取select标签
    var partID=a.options[a.selectedIndex].value;//select标签获取的值其实是一个数组--a.options[]; 然后,选定项的下标是--a.selectedIndex    
    //document.write(partID);
    var Url="SelectPart.asp?Pid="+partID;    window.location.href=Url;
} 

HTML代码:

<select id="SelectClassId" name="SelectClassId">
    <option value="1">分类一</option>
    <option value="2">分类二</option>
    <option value="3">分类三</option>
    <option value="4">分类四</option>
    <option value="5">分类五</option>
</select>
<input type="button" id="Sure" name="Sure" value="确认" onclick="GoToList()" />
 



posted @ 2016-06-25 14:13  小宇飞刀  阅读(132)  评论(0编辑  收藏  举报