我们可以获得jQuery Chosen插件的最后一个未选择的值吗?

naC*_*eex 5 javascript jquery jquery-chosen

我想要获得最后一个未被选中的值.我已经尝试了很多方法但是这可以给我最后选择的值(通过使用最后一个索引)不是最后未选择的.有什么办法吗?

$('#f_district').chosen().change( function(evt, params) {
    if(params.deselected)
    {            
        alert($(this).val());  // it returns null how I can get last unselect value? 
    }
    else
    {
        var arr=$(this).val();
        alert(arr[arr.length-1]);
    }
});
Run Code Online (Sandbox Code Playgroud)

rjd*_*llo -1

你在寻找这样的东西吗http://jsfiddle.net/Z2PkZ/1/

var previous;

$(".chosen").one('focus', function () {
    // Store the current value on focus and on change
    previous = this.value;
}).change(function() {
    // Do something with the previous value after the change
     console.log(previous);

    // Make sure the previous value is updated
    previous = this.value;
});
Run Code Online (Sandbox Code Playgroud)