我正在使用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方法,但似乎没有。我在这里有一个小提琴:http : //jsfiddle.net/Lbwcffcm/1/
有人设法使这个工作正常吗?
Select2具有自定义事件,包括一个名为select2:select的事件。
select2:select
选择结果时将触发。
$('.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;
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句