<html>
<head>
<script type='text/javascript' language='javascript' src="http://localhost/javascript/jquery-1.4.2.js">
</script>
<script type='text/javascript' language='javascript'>
$(document).ready(function(){
$("#button").mousedown(function(){
dropDownMenu = $("#dropDownMenu");
alert(dropDownMenu.options[0].text);
});
});
</script>
</head>
<body>
<select id="dropDownMenu"><option>Test</option></select><br>
<input id="button" type="button">
</body>
</html>
答案 0 :(得分:2)
尝试使用text()功能:
$("#button").mousedown(function() {
var selectedItemText = $('#dropDownMenu :selected').text();
alert(selectedItemText);
});
答案 1 :(得分:0)
Your code dropDownMenu = $("#dropDownMenu");
alert(dropDownMenu.options[0].text);
这里dropDownMenu是一个JQuery对象。所以没有定义dropDownMenu.options。使用dropDownMenu [0]或dropDownMenu.get(0)来获取第一个DOM元素
<select>...</select>