日期:2014-05-17 浏览次数:20380 次
<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 language="javascript"> <!-- var o = document.getElementsByTagName('select'); alert(o[o.length-1].id); // --> </script> </BODY>
------解决方案--------------------
<!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>
------解决方案--------------------
如果页面上还有其他的 就先定位到divid
var o = document.getElementById('divid').getElementsByTagName('select');
------解决方案--------------------
var sel = document.getElementsByTagName('select');
for(var i=0;i<sel.length;i++)
{
..
...
....这里 应该不用我来写了吧 其实根据上面几楼的 答案 自己可以改改 就出来答案了
}