Does anyone know how to get the selected values from a select box that has multiple set.
thanks
<html>
<head>
<script type="text/javascript">
function getSelectedValues()
{
$("#selectID").?????
}
</script>
</head>
<body>
<select id="selectID" MULTIPLE>
<option>Volvo</option>
<option>Saab</option>
<option>Mercedes</option>
<option>Audi</option>
</select>
<a href="javascript:getSelectedValues()>press</a>
</body>
</html>
$("#selectID").val();
From the jQuery API documentation on the val()
method:
The .val() method is primarily used to get the values of form elements. In the case of <select multiple="multiple">
elements, the .val()
method returns an array containing each selected option.
You want to use the selected selector
http://api.jquery.com/selected-selector/
$("#selectID option:selected").each(function () {
$(this).val(); //this is one of the selected values
});
$("#selectID").val()
返回以逗号分隔的所选值列表。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.