laravel - Laravel 5.5 本地化和 CKEditor
问题描述
我想用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>
解决方案
我可以从 CKEditor 的角度解释它是如何工作的。
请参阅:https ://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR.html#cfg-replaceClass和http://nightly.ckeditor.com/18-09-06-06-04/full/samples /old/replacebyclass.html。
CKEditor 可以替换多个文本区域,前提是它们分配了一个特定的 CSS 类(ckeditor
默认情况下)。您需要做的就是在 HTML 文档的标题部分附加 CKEditor 脚本,然后添加一堆<textarea class="ckeditor" name="editor1"></textarea>
元素。它们应该自动更改为编辑器。
或者,您可以textarea
使用 random 生成元素id's
,收集这些元素,id's
然后使用迭代步骤replace
在循环中运行该方法。id
推荐阅读
- python - 使用 tkinter 发出请求的工作方式与终端不同
- android - xml android指南约束布局
- python - 传输时 FTP 无传输超时 - Python ftplib
- javascript - Zoom 使用什么弹出框?
- java - 在Java中的两个字符之间添加空格
- php - 如何使用 PHP 显示从 MySQSL 数据库中获取的更多文本
- java - 如何在eclipse中调用在其他文件上创建的数组?
- python - Python Pydot如何旋转边缘标签
- c++ - 将所有未知的方法调用和属性使用转发到 C++ 中的特殊函数
- ruby-on-rails - 部署到 Heroku 时出现 Rails rake 问题