使用大小属性时,选择下拉列表不同

时间:2016-08-02 10:25:25

标签: javascript jquery html css

我在这里使用了size属性来限制列表:

enter image description here



<div class="select-editable"> 
  <select size="3"> 
    <option value="115x175 mm">115x175 mm</option> 
    <option value="120x160 mm">120x160 mm</option> 
    <option value="120x287 mm">120x287 mm</option> 
    <option value="115x175 mm">115x175 mm</option> 
    <option value="120x160 mm">120x160 mm</option> 
    <option value="120x287 mm">120x287 mm</option> 
  </select>
</div>
&#13;
&#13;
&#13;

但我想在选择元素下可见下拉。

enter image description here

&#13;
&#13;
<div class="select-editable"> 
  <select> 
    <option value="115x175 mm">115x175 mm</option> 
    <option value="120x160 mm">120x160 mm</option> 
    <option value="120x287 mm">120x287 mm</option> 
    <option value="115x175 mm">115x175 mm</option> 
    <option value="120x160 mm">120x160 mm</option> 
    <option value="120x287 mm">120x287 mm</option> 
  </select>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

您可以使用jquery-ui selectmenu等插件。使用此插件,您可以使用css自定义组合,包括限制option框的高度。

演示:(注意我在css中定义的高度)

&#13;
&#13;
$( "#speed" ).selectmenu();
&#13;
.ui-selectmenu-menu .ui-menu {
  height: 74px;
}
&#13;
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<select name="speed" id="speed">
  <option>Slower</option>
  <option>Slow</option>
  <option selected="selected">Medium</option>
  <option>Fast</option>
  <option>Faster</option>
</select>
&#13;
&#13;
&#13;

http://output.jsbin.com/biqaka

<强>更新

Bootstrap演示:( bootstrap-select你有size属性)

&#13;
&#13;
$('.selectpicker').selectpicker({
  style: 'btn-info',
  size: 3
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css">

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"></script>

<select class="selectpicker">
  <option>option</option>
  <option>option</option>
  <option>option</option>
  <option>option</option>
  <option>option</option>
  <option>option</option>
  <option>option</option>
  <option>option</option>
  <option>option</option>
</select>
&#13;
&#13;
&#13;