那么我该如何更改启用多选的下拉标签应显示的行数:
<select multiple="multiple">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
这将仅显示前四个选项,如何在不滚动的情况下显示第五个选项?
那么我该如何更改启用多选的下拉标签应显示的行数:
<select multiple="multiple">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
这将仅显示前四个选项,如何在不滚动的情况下显示第五个选项?
您可以使用CSS指定确切的高度,但由于不同的选择呈现方式,这可能在所有浏览器中都无法完全相同:
<select multiple="multiple" style="height: 24pt">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
Fiddle: http://jsfiddle.net/24Myw/
<select size="any number" name="#" id="#">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
IT工作正常运行。
这里有一个使用JavaScript更具动态性的解决方案:
// put your select into a variable for faster reference.
var mySelect = document.getElementById("my_select");
//decide on the maximum number of options you want displayed and store it in a variable.
//that makes it easier to change if you change your mind on the max or if you want a more dynamic max.
var maxOptions = 5;
// if you have maxOptions or fewer options.
if(mySelect.options.length <= maxOptions){
//set your select size to your option length.
mySelect.size = mySelect.options.length;
}else{
// if you have more than maxOptions options, set your select size to maxOptions.
mySelect.size = maxOptions;
}
注意!请注意,“multiple”属性不仅显示多个选项,还使您能够选择多个选项!