JS获取页面select元素

来源:互联网 发布:你凭什么看不起程序员 编辑:程序博客网 时间:2024/05/22 06:30
<select id="edu" name="edu"><option value="高级">博士</option><option value="中级">硕士</option><option value="初级" selected="selected">本科</option><option value="低级">大专</option></select>



<script>var a=document.getElementById('edu');alert("选择栏位的值:"+a.value);//显示selelct内的option栏位页面alert("a.innerHTML:"+a.innerHTML);/*遍历option 方法1*//*var b=a.getElementsByTagName("option");for(var i=0;i<b.length;i++){var bb=b[i];var bbb=bb.firstChild;alert("option子元素的nodeValue"+bbb.nodeValue);}*//*遍历option 方法2*//*var c=a.options;for(var i=0;i<c.length;i++){//var cc=c[i].value;//获取valuevar cc=c[i].text;//获取option之间的textalert("="+cc);}*/var dd=a.options[a.selectedIndex].text;alert("显示栏位选择的文本:"+dd); </script>