選擇2返回abs
,def
,ghi
值。 如何獲取當前選定的值或數據屬性。
我想只得到abc
或def
有史以來選擇那麼該怎麼辦?選擇2:如何獲得當前選定值
總之
我正在選擇多個,然後最新選擇將顯示。
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link href="http://ivaynberg.github.io/select2/select2-3.5.0/select2.css" rel="stylesheet"/>
<script src="http://ivaynberg.github.io/select2/select2-3.5.0/select2.js"></script>
<script>
$(document).ready(function() {
var target = $("#e1");
var initId = $(target).select2();
$(target).change(function() {
var theID = $(target).select2();
alert(theID);
});
});
</script>
<select id="e1" multiple >
<option value="abc" data-id='1' >ABC</option>
<option value="def" data-id='2'>DEF</option>
<option value="ghi" data-id='3'>GHI</option>
<option value="jkl" data-id='4'>JKL</option>
<option value="mno" data-id='5'>MNO</option>
</select>
我還是不明白,但'$(「option」)。each(fn)'where fn will receive the option element is not enough? – Deeptechtons
@Deeptechtons請添加你的答案,我想試試.. :) –
你的要求是,如果你選擇多個然後最新的選擇將顯示我是嗎? –