【问题标题】:Laravel 5.5 Localization and CKEditorLaravel 5.5 本地化和 CKEditor
【发布时间】:2018-09-05 18:59:48
【问题描述】:

我想用 ckeditor 替换多个 textarea(Content En 和 Content Ru),但它们都有相同的 ID。怎么办,因为加载一个编辑器后就停止了。

表格:

{!! Form::open([ 'route' => 'portfolio.store', 'files' => 'true']) !!}

        @foreach(config('translatable.locales') as $locale)
            <div class="form-group">
                <label for="translation[{{$locale}}][title]"><strong>Title ({{$locale}})</strong></label>
                <input type="text" id="title"
                       name="translation[{{$locale}}][title]"
                       class="form-control"
                       value="{{ old('translation.'. $locale.'.title')  }}">
            </div>

            <div class="form-group">
                <label for="translation[{{$locale}}][content]"><strong>Content ({{$locale}})</strong></label>
                <textarea name="translation[{{$locale}}][content]"
                          id="content"
                          class="form-control"
                          cols="30"
                          rows="10">{{ old('translation.'. $locale.'.content') }}</textarea>
            </div>
        @endforeach

            <div class="form-group">
                <label for="image"><strong>Image</strong></label>
                <input type="file" id="image" name="image" class="form-control-file">
            </div>
            <br>

            <input class="btn btn-success btn-lg btn-block" type="submit" value="Add Portfolio">
    {!! Form::close() !!}

脚本:

<script>
    CKEDITOR.replace( 'content' );
</script>

enter image description here

【问题讨论】:

    标签: laravel ckeditor


    【解决方案1】:

    我可以从 CKEditor 的角度解释它是如何工作的。

    请参阅:https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR.html#cfg-replaceClasshttp://nightly.ckeditor.com/18-09-06-06-04/full/samples/old/replacebyclass.html

    CKEditor 可以替换多个文本区域,前提是它们分配了一个特定的 CSS 类(默认为ckeditor)。您需要做的就是在 HTML 文档的标题部分附加 CKEditor 脚本,然后添加一堆 &lt;textarea class="ckeditor" name="editor1"&gt;&lt;/textarea&gt; 元素。它们应该自动更改为编辑器。

    或者,您可以使用随机id's 生成textarea 元素,收集这些id's,然后在循环中运行replace 方法,使用迭代步骤中的id

    【讨论】:

    • 没问题。如果您发现此解决方案是正确的,请将我的帖子标记为已接受的答案,以便其他人知道。
    猜你喜欢
    • 1970-01-01
    • 2018-06-30
    • 1970-01-01
    • 1970-01-01
    • 2018-06-14
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 2020-12-12
    相关资源
    最近更新 更多