如何使 Bootstrap Select2 下拉菜单在单击时转到选定的 URL?

How do I make Bootstrap Select2 dropdown go to the selected URL on click?

我正在使用 Select2 (https://select2.github.io),我试图让它直接转到特定的 URL,而不是将其用作表单。因此,如果有人单击阿拉巴马州,它将转到 alabama.com,如果有人单击怀俄明州,则会转到 wyoming.com,等等

表格非常基本,例如:

<form>
    <select class="js-example-basic-single">
        <option value="AL">Alabama</option>
        <option value="WY">Wyoming</option>
    </select> 
</form>

发起于

$('.js-example-basic-single').select2({
    minimumResultsForSearch: -1
});

我搜索了一种 onclick 方法,但似乎没有。我这里有一个 fiddle:http://jsfiddle.net/Lbwcffcm/1/

有没有人设法让它工作?

Select2 具有自定义事件,其中一个名为 select2:select

select2:select is fired whenever a result is selected.

$('.js-example-basic-single').select2({
    minimumResultsForSearch: -1
}).on('select2:select', function(){
    switch($(this).val())
    {
        case 'AL':
            location.href = 'http://www.alabama.com';
            break;
        case 'WY':
            location.href = 'http://www.wyoming.com';
            break;
    }
});