如何在Bootstrap模式中使用CKEditor?

Max*_*Max 22 modal-dialog jqmodal ckeditor twitter-bootstrap

如果我在基于Bootstrap模板的HTML页面中使用CKEditor插件,它可以很好地工作,但是如果我在这样的Bootstrap模式上插入编辑器

<!-- Modal --> 
<div class="modal fade" id="modalAddBrand" tabindex="-1" role="dialog" aria labelledby="modalAddBrandLabel" aria-hidden="true">   
  <div class="modal-dialog modal-lg">
     <div class="modal-content">
       <div class="modal-header">
         <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
         <h4 class="modal-title" id="modalAddBrandLabel">Add brand</h4>
       </div>
       <div class="modal-body">
             <form>
             <textarea name="editor1" id="editor1" rows="10" cols="80">
             This is my textarea to be replaced with CKEditor.
             </textarea>            <script>
             CKEDITOR.replace('editor1');
             </script>
             </form> 
       </div>
       <div class="modal-footer">
         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
         <button id="AddBrandButton" type="button" class="btn btn-primary">Save</button>
       </div>
     </div>   
   </div> 
</div>
Run Code Online (Sandbox Code Playgroud)

编辑器可以工作,但编辑器弹出窗口中的所有表单控件都被禁用,例如,如果您尝试添加链接或图像,则无法插入URL或任何描述,因为输入已禁用.

针对此问题的任何解决方法?

这是一个小提琴的例子:http://jsfiddle.net/7zDay/

Pav*_*lev 50

这应该有助于http://jsfiddle.net/pvkovalev/4PACy/

$.fn.modal.Constructor.prototype.enforceFocus = function () {
    var $modalElement = this.$element;
    $(document).on('focusin.modal', function (e) {
        var $parent = $(e.target.parentNode);
        if ($modalElement[0] !== e.target && !$modalElement.has(e.target).length
            // add whatever conditions you need here:
            &&
            !$parent.hasClass('cke_dialog_ui_input_select') && !$parent.hasClass('cke_dialog_ui_input_text')) {
            $modalElement.focus()
        }
    })
};
Run Code Online (Sandbox Code Playgroud)

2016年10月更新:

CKEditor的CDN链接已更改,因此我更新了jsfiddle

  • 作品!只需创建一个单独的文件,并在jquery和bootstrap脚本之后包含它.帮助我节省了时间和精力! (2认同)
  • 这对我不起作用。对于另一个通用解决方案检查 http://stackoverflow.com/questions/31678662/ckeditor-issue-with-bootstrap-modal (2认同)
  • 哇,这是我搜索了一个小时后找到的唯一解决方案。谢谢! (2认同)

Hos*_*ebi 5

回答晚了,但做 css 技巧将解决问题。

z-indexBootstrap modal 的默认值是,ckeditor 对话框的10051默认值z-index10010. 诀窍只是增加ckeditor对话框z-index,如下所示。将以下代码放入您的 css 文件中:

.cke_dialog
{
    z-index: 10055 !important;
}
Run Code Online (Sandbox Code Playgroud)

  • 对我来说还不够。我也需要更改 .cke_dialog 和 .cke_dialog_background_cover 的 Z-index (2认同)