How can I limit selecting options in multi select popup of jQuery mobile?

雨燕双飞 提交于 2019-12-25 03:54:34

问题


    <select data-native-menu="true" id="food_type"  multiple="multiple" data-placeholder="Favourite food types" class="chzn-select-tag photo-status-update-tags"  multiple="" tabindex="-1">
                            <option data-placeholder='true' value="" disabled="disabled">Favourite food types</option>
                           <?php foreach($this->aFoods as $aFood):  ?>
                            <option value="<?php echo $aFood['food_name']; ?>" ><?php echo $aFood['food_name']; ?></option>
                           <?php endforeach; ?>
    </select>



jQuery('#food_type').on('change', function() {
if (this.selectedOptions.length <= 5) {
    jQuery(this).find(':selected').addClass('selected');
    jQuery(this).find(':not(:selected)').removeClass('selected');
} else {

    jQuery(this)
    .find(':selected:not(.selected)')
    .prop('selected', false);

}
});

Here is my code.I had limited the selected option to 5.Its working.But in multi select popup it is possible to select more than 5.My requirement is,if anyone tries to select more than 5 options, disable selection in multi select popup.I am using jquery mobile 1.2.1


回答1:


The issue is fixed now..I have changed the style of multi select popup by changing the <select> attribute 'data-native-menu="false"'. Just like below:

<select data-native-menu="false" id="food_type"  multiple="multiple" data-placeholder="Favourite food types" class="chzn-select-tag photo-status-update-tags"  multiple="" tabindex="-1">


来源:https://stackoverflow.com/questions/25524280/how-can-i-limit-selecting-options-in-multi-select-popup-of-jquery-mobile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!