如何在使用selectmenu UI选择菜单之前禁用/启用选择菜单的某些选项?
我在文档中看不到beforeOpen
个事件。有没有办法动态启用/禁用项目?
答案 0 :(得分:0)
您可以在打开事件或插件初始化之前执行此操作:
$(function(){
$('select').selectmenu();
$('#disable').click(function(){
$('select option:eq(1)').attr("disabled", true);
$('select').selectmenu();
})
});

/* demo styles */
body {font-size: 62.5%; font-family:"Verdana",sans-serif; }
fieldset { border:0; }
label,select,.ui-select-menu { float: left; margin-right: 10px; }
select { width: 200px; }
.wrap span.ui-selectmenu-item-header,
.wrap ul.ui-selectmenu-menu li a { text-decoration: underline !important; }

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://github.felixnagel.com/selectmenu/ui/jquery.ui.position.js"></script>
<script src="http://github.felixnagel.com/selectmenu/ui/jquery.ui.widget.js"></script>
<link href="http://github.felixnagel.com/selectmenu/themes/base/jquery.ui.theme.css" rel="stylesheet"/>
<link href="http://github.felixnagel.com/selectmenu/themes/base/jquery.ui.core.css" rel="stylesheet"/>
<script src="http://github.felixnagel.com/selectmenu/ui/jquery.ui.core.js"></script>
<link href="http://github.felixnagel.com/selectmenu/themes/base/jquery.ui.selectmenu.css" rel="stylesheet"/>
<script src="http://github.felixnagel.com/selectmenu/ui/jquery.ui.selectmenu.js"></script>
<select name="data[sport]" class="selectmenu" id="sport">
<option value="Kayaking">Kayaking</option>
<option value="Rock climbing">Rock climbing</option>
<option value="Surfing">Surfing</option>
<option value="Skateboarding">Skateboarding</option>
</select>
<button id='disable'>Disable second option</button>
&#13;