2

我有一个项目,我在其中使用带有表单和 ckeditor 的模式,并且链接输入不起作用。

这是一个重现此问题的小提琴:

http://jsfiddle.net/8t882a2s/3/

还有这个例子的代码。

HTML:

        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <h4 class="modal-title" contenteditable="true" id="myModalLabel">Modal title</h4>
                    </div>
                    <div id="bodyModal" contenteditable="true" class="modal-body">
                        ...
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="button" class="btn btn-primary">Save changes</button>
                    </div>
                </div>
            </div>
        </div>

 <button type="button" class="btn btn-default navbar-btn  margin-right-button-nav" data-toggle="modal" data-target="#myModal"><span class="glyphicon glyphicon-new-window"></span> Edit Modal</button>

JS:

CKEDITOR.disableAutoInline = true;

$(document).ready(function() {
    $('#myModal').on('shown.bs.modal', function () {
        CKEDITOR.inline('myModalLabel');
        CKEDITOR.inline('bodyModal');
    })    
});

这不完全是我的代码,但错误是相同的。如果您单击模式然后尝试添加链接,则您无法在输入字段中写入 url。

谢谢 :)

4

4 回答 4

12

互联网上的很多答案都建议了多种修复方法,这对我有用,对于 bootstrap 4 项目:

$.fn.modal.Constructor.prototype._enforceFocus = function() {
                var $modalElement = this.$element;
                $(document).on('focusin.modal',function(e) {
                    if ($modalElement.length > 0 && $modalElement[0] !== e.target
                        && !$modalElement.has(e.target).length
                        && $(e.target).parentsUntil('*[role="dialog"]').length === 0) {
                        $modalElement.focus();
                    }
                });
            };

如果您在引导程序 3 上运行,则覆盖$.fn.modal.Constructor.prototype.enforceFocusinsdead。

于 2017-03-29T21:41:40.127 回答
3

To solve this issue is enough to do the following things:

  1. Add custom css rules on your body tag

    body { --ck-z-default: 100; --ck-z-modal: calc( var(--ck-z-default) + 999 ); }

  2. Set your modal options focus value to false

    • if you are using javascript to launch modal you should do it like this:

    $( '#basicModal' ).modal( { focus: false } );

    • if you are using data attributes to launch modal you should have it like this <div class="modal fade " data-focus="false" id="basicModal">
于 2019-10-18T08:25:07.440 回答
0

对我来说,tabindex="-1"从 modal 属性中删除可以解决问题。

于 2022-01-07T13:10:37.993 回答
0

这是正确的!对我来说 data-focus="false" 解决了所有问题

于 2020-04-22T17:53:37.707 回答