selectmenu的open
方法无效。
$( "#speed" ).selectmenu('open'); // doesn't work
想法?
HTML
<button id="btn">open it</button>
<fieldset>
<label for="speed">Select a speed</label>
<select name="speed" id="speed">
<option value="Slower">Slower</option>
<option value="Slow">Slow</option>
<option value="Medium" selected="selected">Medium</option>
<option value="Fast">Fast</option>
<option value="Faster">Faster</option>
</select>
</fieldset>
JS
$(function () {
$( "#speed" ).selectmenu();
$('#btn').click(function(){
$( "#speed" ).selectmenu('open'); // doesn't work
});
});
CSS
fieldset {
border: 0;
}
label {
display: block;
margin: 30px 0 0 0;
}
select {
width: 200px;
}
.overflow {
height: 200px;
}
答案 0 :(得分:3)
我看了一下发生了什么。它打开正常,但在打开期间,它会注册一个文档点击处理程序,关闭菜单以响应菜单外的任何点击,并且此处理程序立即处理按钮上的点击。你应该能够像这样停止处理这个点击的处理程序:
$(function () {
$( "#speed" ).selectmenu();
$('#btn').click(function(event){
$( "#speed" ).selectmenu('open');
event.stopPropagation();
});
});