【发布时间】:2022-01-24 00:09:50
【问题描述】:
如何增加带有 jQuery 用户界面样式的选择菜单的高度?我想增加实际元素的高度,而不是单击它时出现的选项下拉菜单的高度(网站上已经有一些答案)。基本上,我希望菜单看起来是方形的,几乎就像一个按钮。
我尝试在将 UI 应用到 javascript 中的元素时设置高度。但是,我使用的任何高度值似乎都被忽略了:
$(document).ready(function() {
let testSelect = document.createElement('select');
let firstOption = document.createElement('option');
firstOption.text = 'blablablabla...';
firstOption.defaultSelected = true;
testSelect.appendChild(firstOption);
document.getElementById('testDiv').appendChild(testSelect);
$(testSelect).selectmenu({height: '50%'}); // no matter what value of height I use, the menu does not change
testButton = document.createElement('button');
testButton.innerHTML = 'Like this example button';
$(testButton).button();
document.getElementById('testDiv').appendChild(testButton); // I want the select menu to look similar to a button like this
});
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/ui/1.13.0/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.13.0/themes/redmond/jquery-ui.css">
<div id="testDiv" style="width:100px; height:100px;"></div>
【问题讨论】:
标签: javascript html css jquery-ui