gpt4 book ai didi

jquery-select2 - 在 optgroup 中选择 2 optgroup

转载 作者:行者123 更新时间:2023-12-01 15:44:06 28 4
gpt4 key购买 nike

select2上是否可以有多层 optgroup?
基本上,另一个 optgroup 中的 optgroup。

<select>
<optgroup label="Level_1">
<optgroup label="Level_2">
<option value="option_1">option_1</option>
<option value="option_2">option_2</option>
</optgroup>
</optgroup>
</select>

Fiddle

谢谢。

最佳答案

html 不支持嵌套的 optgroup,但您可以使用 JavaScript 来创建它们。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
$(document).ready(function () {
$('#NestedOptGroups').select2({
data: [
{
text: 'Level_1', children: [
{
text: 'Level_2', children: [
{id: 'Level2Opt0', text: 'Sub Option 1'},
{id: 'Level2Opt1', text: 'Sub Option 2'}
]
},
{id: 'Level1Opt0', text: 'Main Level option 1'}
]
}
]
});
});
</script>

</head>
<body>
<input class="select2" id="NestedOptGroups" placeholder="select one"/>
</body>
</html>

关于jquery-select2 - 在 optgroup 中选择 2 optgroup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28157015/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com