The selectmenu's open method isn't working.

$( "#speed" ).selectmenu('open'); // doesn't work

Ideas?

fiddle

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;
}
有帮助吗?

解决方案

I took a look at what's going on. It's opening ok, but during open it's registering a document click handler that closes the menu in response to any click outside the menu, and the click on the button is immediately handled by this handler. You should be able to stop the handler handling this very click like so:

$(function () {
    $( "#speed" ).selectmenu();
    $('#btn').click(function(event){
        $( "#speed" ).selectmenu('open');
        event.stopPropagation();
    });
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top