<SELECT multiple> - how to allow only one it

2020-05-11 07:28发布

I have a <SELECT multiple> field with multiple options and I want to allow it to have only one option selected at the same time but user can hold CTRL key and select more items at once.

Is there any way how to do it? (I don't want to remove 'multiple').

8条回答
姐就是有狂的资本
2楼-- · 2020-05-11 08:03

I had some dealings with the select \ multi-select this is what did the trick for me

<select name="mySelect" multiple="multiple">
    <option>Foo</option>
    <option>Bar</option>
    <option>Foo Bar</option>
    <option>Bar Foo</option>
</select>
查看更多
孤傲高冷的网名
3楼-- · 2020-05-11 08:03

Late to answer but might help someone else, here is how to do it without removing the 'multiple' attribute.

$('.myDropdown').chosen({
    //Here you can change the value of the maximum allowed options
    max_selected_options: 1
});
查看更多
登录 后发表回答