[英]get previous and present selected value of the dropdown using chosen in jquery
[英]Jquery Chosen get the Id of un-selected value in dropdown
我已經設法獲得所選插件的 ID的選擇。 這是jsfiddle演示 。
現在,我不確定如何獲取未選中選項的ID。 我正在使用此代碼來獲取所選選項的ID。
var SelectedIds = $(this).find('option:selected').map(function() {
if ($(this).attr('value') == params.selected)
return $(this).prop('id')
}).get();
alert(SelectedIds);
取消選擇選項后,您將獲得更改事件,但是params
對象具有deselected
屬性,可以像使用selected
一樣使用它。
我為您演示了一個jsfiddle: http : //jsfiddle.net/1eut1c3d/
$("#chosen").chosen().on('change', function(evt, params) {
if (params.selected !== undefined) {
var selectedID = $(this).find('option:selected').map(function() {
if ($(this).attr('value') == params.selected)
return $(this).prop('id')
}).get();
alert("Selected: " + selectedID);
}
if (params.deselected !== undefined) {
var deselectedID = $(this).find('option').not(':selected').map(function() {
if ($(this).attr('value') == params.deselected)
return $(this).prop('id')
}).get();
alert("Deselected: " + deselectedID);
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.