0

selectmenuopen方法不起作用。

$( "#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;
}
4

1 回答 1

3

我看了看发生了什么事。它可以打开,但是在打开期间它正在注册一个文档单击处理程序,该处理程序会关闭菜单以响应菜单外的任何单击,并且单击按钮会立即由该处理程序处理。您应该能够像这样停止处理此点击的处理程序:

$(function () {
    $( "#speed" ).selectmenu();
    $('#btn').click(function(event){
        $( "#speed" ).selectmenu('open');
        event.stopPropagation();
    });
});
于 2013-09-27T01:56:39.220 回答