如何使这个多选择列表可调整大小?我希望设置列表的默认高度和宽度以及最小高度和宽度,但可以自行调整其大小。
我尝试过,但没有成功:
<div id="resizable" class="ui-widget-content">
<h3 class="ui-widget-header">Stored Procedures</h3>
<div class='list'>
<select multiple="multiple" height="5" data-bind="options:storedProceduresInDB1, selectedOptions:selectedStoredProceduresInDb1"> </select>
<div>
<button data-bind="click: copyToDb2, enable: selectedStoredProceduresInDb1().length > 0">Copy to DB2</button>
</div>
</div>
</div>
$(function() {
$( "#resizable" ).resizable();
});JSFiddle
发布于 2014-02-24 14:43:40
在您的jsFiddle中,我看不到$('#resizable').resizable();,您也没有任何ID为resizable的东西。但是,由于您已经用jQuery标记了它,所以可以通过包含jQuery、.js和.css文件来实现这一点。另外,将resizable的ID添加到控件中,该控件可以调整大小,并引用插件。若要设置最小高度和宽度,请参见下面的代码。我对您的jsFiddle的更改包括:
id="resizable"添加到select中$( "#resizable" ).resizable();.ui-resizable-se { bottom: 'some amount'; right: 'some amount'; }下面是一个更新的jsFiddle,它不包括我提到的css或设置最小高度和宽度。
守则如下:
<select id="resizable" multiple="multiple" height="5"
data-bind="options:storedProceduresInDB1,
selectedOptions:selectedStoredProceduresInDb1"></select>
$(function() {
$('#resizable').resizable({
// to set the min height and width
minHeight: 100,
minWidth: 200
// you could also set a maxHeight and maxWidth as well
});
});为了在select中定位拖放图标,我添加了以下css:
.ui-resizable-se { bottom: 18px; right: 25px; }发布于 2019-12-30 15:57:01
如果有人无意中发现了这个问题,并且(合法地)不想使用JQuery来解决这个问题,您可以只使用“调整大小”CSS属性:resize.asp。
就提交人而言:
<select id="resizable" multiple="multiple" height="5" databind="options:storedProceduresInDB1, selectedOptions:selectedStoredProceduresInDb1"> </select>
#resizable{
resize: both;
}实际上,不需要向"select“元素添加一个id,我们只需在JSFiddle中CSS文件的第6行添加"resize”属性:
.list select[multiple] { width: 100%; height: 8em; resize: both; }
最后,您可以使用经典的css属性min高度和最小宽度来设置选择的最小大小:
.list select[multiple] { width: 100%; height: 8em; min-width: 100px; min-height: 100px; resize: both; }
发布于 2021-03-11 09:23:20
只需添加CSS规则:
select { resize: auto; }https://stackoverflow.com/questions/21989648
复制相似问题