jquery-select2之在 optgroup 中选择 2 optgroup
powertoolsteam
阅读:26
2025-05-04 20:05:19
评论:0
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>
谢谢。
请您参考如下方法:
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>
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。