我在模式中使用Select2,但是它不能正常工作,如您在此处看到的:https://gyazo.com/a1f4eb91c7d6d8a3730bfb3ca610cde6

结果出现在模态后面。我怎样才能解决这个问题?我读过类似的文章,但是所有人都在谈论删除tabindex,这是我的代码中没有的内容,因此我不知道如何解决。这是我的代码:

<div class="remodal shadow" data-remodal-id="keuze" data-remodal-options="closeOnOutsideClick: false">
    <button data-remodal-action="close" class="remodal-close"></button>
    <div class="panel-header">Kies uw type logboek</div>
    <div class="modal-body">
        <select id="select" class="searchselectstyle select2"></select>
        <button data-remodal-action="cancel" class="remodal-cancel mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect cancel">Cancel</button>
        <button data-remodal-action="confirm" class="remodal-confirm mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect send">Aanmaken</button>
    </div>
</div>

<script type="text/javascript">
    token = '{{csrf_token()}}';
    $(document).ready(function() {
        $('#select').select2({
            ajax: {
                type: "POST",
                url: "ajax/getlogtypes",
                dataType: 'json',
                data: function (params) {
                    return {
                        q: params.term, // search term
                        page: params.page,
                        '_token' : token
                    };
                },
                escapeMarkup: function (markup) {
                    return markup;
                }, // let our custom formatter work
                minimumInputLength: 1
            }
        });
    });
</script>

最佳答案

在按照Rory McCrossan的建议检查DOM之后,我发现Select2生成的span元素的z索引较低。我通过在代码中添加以下内容来修复它:

.select2-container{
    z-index:100000;
}

关于javascript - 具有AJAX的Select2出现在模态后面,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36311093/

10-09 17:23