日期:2014-05-17  浏览次数:20691 次

多个select如何获取最后一个,在线等
<div id="divid">
<select id="a1" name="a1">
<option value="0" selected="selected">选择分类</option>
<option value="90">MID TABLET PC</option>
</select>
<select id="a2" name="a2">
<option value="0" selected="selected">选择分类</option>
<option value="90">MID TABLET PC</option>
</select>
<select id="a3" name="a3">
<option value="0" selected="selected">选择分类</option>
<option value="90">MID TABLET PC</option>
</select>
</div>
请问我如何才能获取到最后一个select的值?谢谢

------解决方案--------------------
HTML code

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="gb2312" />
        <title></title>
    </head>
    <body>
        <div id="divid">
            <select id="a1" name="a1">
            <option value="0" selected="selected">选择分类</option>
            <option value="90">MID TABLET PC</option>
            </select>
            <select id="a2" name="a2">
            <option value="0" selected="selected">选择分类</option>
            <option value="90">MID TABLET PC</option>
            </select>
            <select id="a3" name="a3">
            <option value="0" selected="selected">选择分类</option>
            <option value="90">MID TABLET PC</option>
            </select>
        </div>
        <script>
            var $ = function(id){
                return document.getElementById(id);
            };
            var $t = function(tag, cot){
                cot = cot || document;
                return cot.getElementsByTagName(tag);
            };
            
            var objs = $t('select', $('divid'));
            alert( objs[objs.length-1].id )
            
        </script>
    </body>
</html>