<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <script> function test() { var o = document.getElementById("myselect"); var i = o.selectedIndex; alert(o.options[i].getAttribute("name")); } </script><style type="text/css"></style></head><body><select name="select4" size="10" id="myselect" style="width:300px; border:1px solid #bbbbbb;"> <option name="15" value="1">1123</option> <option name="16" value="2">23erewewrwe</option> <option name="17" value="3">33</option> <option name="18" value="4">2323</option> </select><input type="button" value="test" onclick="test();" /> </body>
</html>
var o = document.getElementById("myselect");//alert(o.id); var ioptions = o.getElementsByTagName('option');alert(ioptions.length); for(var i = 0; i < ioptions.length; i++) { alert(ioptions[i].name); }
select的name直接用document.getElementById("myselect").name吧
<select name="select4" size="10" id="myselect" style="width:300px; border:1px solid #bbbbbb;">
<option name="15" value="1">1123</option>
<option name="16" value="2">23erewewrwe</option>
<option name="17" value="3">33</option>
<option name="18" value="4">2323</option>
</select>
<html>
<head>
<script>
function test()
{
var o = document.getElementById("myselect");
var i = o.selectedIndex;
alert(o.options[i].getAttribute("name"));
}
</script><style type="text/css"></style></head><body><select name="select4" size="10" id="myselect" style="width:300px; border:1px solid #bbbbbb;">
<option name="15" value="1">1123</option>
<option name="16" value="2">23erewewrwe</option>
<option name="17" value="3">33</option>
<option name="18" value="4">2323</option>
</select><input type="button" value="test" onclick="test();" />
</body>
</html>
var o = document.getElementById("myselect");//alert(o.id);
var ioptions = o.getElementsByTagName('option');alert(ioptions.length);
for(var i = 0; i < ioptions.length; i++)
{
alert(ioptions[i].name);
}