使用页面上的添加按钮在 codeigniter 中添加另一个 ckeditor

每当您单击添加按钮时,我想添加另一个 ckeditor 将添加另一个带有 ckeditor 的文本字段。单击它时,它已经添加了新字段,但我无法使用 ckeditor 在新字段上输入。这是我的代码:


* 看法 *


                   <div id="addanother">

                        <?php echo $this->ckeditor->editor("textheading_lead[]",""); ?>

                        <br>

                        <div class="form-group">

                            <label for="sel1">小見出し</label>

                            <select class="form-control" name="subheading[]">

                                <option value="">監修 one</option>

                                <option value="">監修 two</option>

                                <option value="">監修 three</option>

                                <option value="">監修 four</option>

                            </select>

                        </div>

                        <input type="text" class="form-control" name="subheading_text[]">

                    </div>

                    <div id="addnewdiv"></div>

                    <a href="" class="btn btn-info addfields" >+</a>

* javascript *


$('.addfields').on('click', addfields);

function addfields(e) {

  var new_input = $('#addanother').html();

  var aaa = new_input + '<br>';

  $('#addnewdiv').append(new_input);

  e.preventDefault();

}

* 控制器 *


public function add_special(){

        $this->load->library('ckeditor');

        $this->load->library('ckfinder');

        $this->ckeditor->basePath = base_url().'asset/ckeditor/';


        $this->ckeditor->config['language'] = 'en';

        $this->ckeditor->config['width'] = '730px';

        $this->ckeditor->config['height'] = '300px';


        $this->ckfinder->SetupCKEditor($this->ckeditor,'../../asset/ckfinder/'); 


        $this->load->view('common/header');

        $this->load->view('admin/special/add_special');

        $this->load->view('common/footer');

    }

CKEditor 包的链接


https://ckeditor.com/ckeditor-4/download/


小怪兽爱吃肉
浏览 166回答 1
1回答

MM们

不幸的是,ckeditor插件用于为编辑器面板创建动态 ID。在附加 div 时,插件会找到具有相同 ID 的重复编辑器实例,textheading_lead[]并且在您的情况下抛出错误。在这里,我做了一些改动,将为您服务。<?phpdefined('BASEPATH') OR exit('No direct script access allowed');?><html>&nbsp;&nbsp;<head>&nbsp; <title>How to Integrate CKeditor in Codeigniter using Bootstrap</title>&nbsp; <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">&nbsp; <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>&nbsp; <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>&nbsp; <script type="text/javascript" src="<?php echo base_url(); ?>assets/ckeditor/ckeditor.js"></script>&nbsp; <script type="text/javascript" src="<?php echo base_url(); ?>assets/ckfinder/ckfinder.js"></script></head><body><div class="container"><form method="post" action="<?php echo base_url(); ?>/Test57619322/here">&nbsp; &nbsp; <div class="row">&nbsp; &nbsp; &nbsp; &nbsp; <div class="col-lg-12">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div id="addanother">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php echo $this->ckeditor->editor("textheading_lead[0]",""); ?>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="form-group">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <label for="sel1">小見出し</label>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <select class="form-control" name="subheading[]">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="">監修 one</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="">監修 two</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="">監修 three</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="">監修 four</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </select>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="text" class="form-control" name="subheading_text[]">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div id="addnewdiv"></div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; </div>&nbsp; &nbsp; <div class="row" style="margin-top:20px;">&nbsp; &nbsp; &nbsp; &nbsp; <div class="col-lg-12">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="" class="btn btn-info addfields" >+ Add Fields</a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="submit" name="submitBtn" value="Submit" class="btn btn-success">&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp;&nbsp;</form></div><script type="text/javascript">&nbsp; &nbsp; $('.addfields').on('click', addfields);&nbsp; &nbsp; var i=0;&nbsp; &nbsp; function addfields(e) {&nbsp; &nbsp; &nbsp; e.preventDefault();&nbsp; &nbsp; &nbsp; var copy = $('#addanother').clone();&nbsp; &nbsp; &nbsp; var oneplus=i+1;&nbsp; &nbsp; &nbsp; $(copy).find('div#cke_textheading_lead\\[0\\]').remove();&nbsp; &nbsp; &nbsp; $(copy).find('script').remove();&nbsp; &nbsp; &nbsp; $(copy).find('textarea[name=textheading_lead\\[0\\]]').attr('name', 'textheading_lead['+oneplus+']');&nbsp; &nbsp; &nbsp; $('#addnewdiv').append($(copy).html()+ '<br>');&nbsp; &nbsp; &nbsp; CKEDITOR.replace('textheading_lead['+oneplus+']');&nbsp; &nbsp; &nbsp; i++;&nbsp;&nbsp;&nbsp; &nbsp; }</script></body></html>您可以在您的控制器中接收响应,例如$_POST["textheading_lead"]Codeigniter post 方法,并且像往常一样,它以数组的形式获取。
打开App,查看更多内容
随时随地看视频慕课网APP