如何使用getElementById获取子节点的值

时间:2014-03-18 19:04:24

标签: javascript html

晚上...当我点击申请时,我想知道从下拉菜单(选择标签)中选择了哪个节点或值...我似乎没有正确引用它们...请帮忙!

<script type="text/javascript">
function apply(){
var xy = document.getElementById("hmm").childNodes;
var ab = xy.value;
alert(ab);
}
</script>
</head>


<body>
<div id="unique">
<select id="hmm" name="drop">
<option value="" id="text area">Text Area</option>
<option value="" id="paragraph">Paragraph</option>
<option value="" id="radio">Radio Button</option>
<option value="" id="delete">Delete</option>
</select>
<button id="apply" onclick="apply()">Apply</button> 
</div>
</html>

1 个答案:

答案 0 :(得分:0)

function apply() {
    var selectBox = document.getElementById("hmm");
    var selectedOption = selectBox.options[selectBox.options.selectedIndex];
    alert(selectedOption.value);
}

Working Fiddle