开发者

jquery, how to get the values from a multi select box

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 getS开发者_如何学CelectedValues()
{
  $("#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() returns a comma delimited list of selected values.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜