JavaScript - 强制选择元素下拉?

dpp*_*dpp 8 javascript select drop-down-menu

如何使用Javascipt强制select元素下拉?可能吗?

<select id="MiamiPlayers">
    <option value="0">Bosh</option>
    <option value="1">Wade</option>
    <option value="2">LeBron</option>
</select>

<input type="button" onclick="Show()" />

<script type="text/javascript">
    function Show()
    {
        //force the select to dropdown...
    }
</script>
Run Code Online (Sandbox Code Playgroud)

提前致谢!

Pet*_*tah 5

你不能打开下拉菜单,但你可以这样做:

document.getElementById('MiamiPlayers').setAttribute('size', 3);
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/MdCBB/


Din*_*ash 0

var select = document.getElementById(id);
select.size = select.options.length;
Run Code Online (Sandbox Code Playgroud)

其中 id 是您的选择框的 id...