簡體   English   中英

jQuery,如何從多重選擇框中獲取值

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

有誰知道如何從具有多個設置的選擇框中獲取選擇的值。

謝謝

<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();

val()方法的jQuery API文檔中:

.val()方法主要用於獲取表單元素的值。 對於<select multiple="multiple">元素, .val()方法將返回一個包含每個選定選項的數組。

您要使用選擇的選擇器

http://api.jquery.com/selected-selector/

$("#selectID option:selected").each(function () {
            $(this).val(); //this is one of the selected values
          });

$("#selectID").val()返回以逗號分隔的所選值列表。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM