728x90
반응형
function adjustMultiselectWidth(multiselect) {
var maxOptionWidth = 0;
// 모든 옵션의 너비를 비교하여 최대 너비를 계산합니다.
$(multiselect).find('option').each(function() {
var optionWidth = $(this).text().length * 8; // 폰트 크기와 관련된 값을 조정하여 옵션 텍스트의 길이에 따른 예상 너비를 계산합니다.
if (optionWidth > maxOptionWidth) {
maxOptionWidth = optionWidth;
}
});
// 최대 너비를 멀티셀렉트에 적용합니다.
$(multiselect).css('width', maxOptionWidth + 'px');
}
// adjustMultiselectWidth 함수를 호출하여 멀티셀렉트의 너비를 조정합니다.
adjustMultiselectWidth('#your-multiselect-id');
728x90
반응형
'Front > JS & jQuery' 카테고리의 다른 글
[js] encodeURIComponent (0) | 2024.05.14 |
---|---|
[js] location.href (0) | 2024.05.13 |
[jQuery] 선택자(selector) 확장검색 (0) | 2024.05.10 |
[jQuery][datatables] td안에 bootstrap multiselect 넣기 (0) | 2024.05.05 |
[js][Echarts] Click event, 클릭한 차트의 Id 구하기 (0) | 2024.05.04 |