【问题标题】:Loosing focus in CKEditor after using jQuery to paste a content使用 jQuery 粘贴内容后在 CKEditor 中失去焦点
【发布时间】:2020-07-10 16:26:46
【问题描述】:



我正在使用 CKEditor 在我的文章页面上编辑一些 cmets。 当我单击“编辑”按钮时,会显示一个带有 CKEditor 字段的模式。我使用一些 jQuery 来“复制粘贴”初始评论的内容,以便用户现在可以对其进行编辑。
问题出在这里,内容粘贴在 CKEditor 中,但焦点丢失,我找不到更改文本的方法。

这是我的树枝视图:

{% if comment.user == app.user %}
    <div class="col-12 mt-3">
        <div class="row justify-content-center justify-content-lg-end">
            <div class="col-10 col-lg-4">
            <!-- Button trigger modal -->
                <button id="editBtn-{{ comment.id }}" data-id="{{ comment.id }}" type="button" class="editBtn btn btn-warning w-100" data-toggle="modal" data-target="#modalCenter">
                <i class="fa fa-pencil-square-o fa-lg mr-2" aria-hidden="true"></i>Éditer
                </button>
            </div>
        </div>
    </div>
{% endif %}

这是我的 jQuery:
$('.editBtn').click(function() {  
    let commentId = "#comment-" + $(this).data("id");
    let editComment = $(commentId).html();
    $('#cke_2_contents ').html(editComment);
});

【问题讨论】:

    标签: javascript jquery ckeditor focus


    【解决方案1】:

    我想出了如何解决这个问题:

    $('#cke_2_contents').attr("contenteditable", true);
    

    添加这个属性就可以了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      相关资源
      最近更新 更多