我有两个select
代码工具select2 jquery plugin
:
select
标记正常:工作正常,可以搜索。
select
标签:无法搜索。
<head>
<link rel="stylesheet" href="https://almsaeedstudio.com/themes/AdminLTE/plugins/select2/select2.min.css">
<link rel="stylesheet" href="https://almsaeedstudio.com/themes/AdminLTE/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="https://almsaeedstudio.com/themes/AdminLTE/dist/css/AdminLTE.min.css">
<script src='https://almsaeedstudio.com/js/bootstrap.min.js'></script>
<script src='https://almsaeedstudio.com/themes/AdminLTE/dist/js/demo.js'></script>
<script src='https://almsaeedstudio.com/themes/AdminLTE/plugins/select2/select2.full.min.js'></script>
<script src='https://almsaeedstudio.com/themes/AdminLTE/dist/js/app.min.js'></script>
<script src='https://almsaeedstudio.com/themes/AdminLTE/bootstrap/js/bootstrap.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
</head>
<body>
<div>
<select id="categoryID" onchange="changeCategory(this)" class="form-control select2" style="width: 100%">
<option id="1">Games</option>
<option id="2">Sport</option>
<option id="3">Sport Games</option>
</select>
<script src='https://almsaeedstudio.com/themes/AdminLTE/dist/js/demo.js'></script>
<script src='https://almsaeedstudio.com/themes/AdminLTE/plugins/select2/select2.full.min.js'></script>
<script src='https://almsaeedstudio.com/themes/AdminLTE/dist/js/app.min.js'></script>
<script src='https://almsaeedstudio.com/themes/AdminLTE/bootstrap/js/bootstrap.min.js'></script>
<button class="btn btn-block btn-primary" data-toggle="modal"
data-target="#addNewCategoryModal">New
</button>
<div class="modal fade" id="addNewCategoryModal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">×</span>
</button>
<h4 class="modal-title" id="titleLabel">New Category</h4>
</div>
<div class="modal-body">
<div class="form-group">
<select id="categoryID" onchange="changeCategory(this)" class="form-control select2" style="width: 100%">
<option id="1">Games</option>
<option id="2">Sport</option>
<option id="3">Sport Games</option>
</select>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
function initialSelect() {
$(".select2").select2();
}
$(function () {
//Initialize Select2 Elements
$(".select2").select2();
});
$('#addNewCategoryModal').on('show.bs.modal', function (event) {
var modal = $(this)
modal.find('.modal-body #categoryID').select2();
modal.find('.modal-body categoryID').select2();
modal.find('.select2').select2();
$(".select2").select2();
})
</script>
</div>
</body>
&#13;
任何帮助。感谢。
答案 0 :(得分:1)
您已为模态提供tabindex="-1"
。因为这个输入没有得到关注。从代码中删除tabindex它应该可以工作。
您的代码中还存在以下问题
categoryID
。 ID必须是唯一的。答案 1 :(得分:0)
这对我有用
<script>
$('#mySelect2').select2({
dropdownParent: $('#myModal')
});
</script>
来源: