如何在单击按钮时动态添加新textarea时添加tinyMCE编辑器实例?

时间:2017-06-21 13:24:55

标签: javascript jquery tinymce

我试图将tinyMCE编辑器添加到新的textareas中,当它们被添加到按钮点击时。 这是我的javascript代码段:

                    $('#day_wrapper').append('' +
                    '<div class="holder-itenary">' +
                    '<label class="control-label" style="font-size: large">Day ' + i + '</label><' +
                    'a href="#" class="remove-itenary"><i class="fa fa-trash pull-right"></i>' +
                    '</a>' +
                    '<textarea rows="2" cols="50" name="descriptions[]" class="form-control" ' +
                    'placeholder="Add Description" id="tinyContent">' +
                    '</textarea></div>');
                tinyMCE.execCommand('mceAddControl', false, 'tinyContent');

这也是我的tinyMCE功能:

                tinymce.init({
                selector: 'textarea',
                /*
                 plugins: [
                 "advlist autolink link image lists charmap print preview hr anchor pagebreak",
                 "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
                 "save table contextmenu emoticons template paste textcolor jbimages directionality",
                 "placeholder"
                 ]
                 */
                plugins: [
                    "table",
                    'advlist autolink lists link charmap print preview anchor',
                    'searchreplace visualblocks code fullscreen',
                    'insertdatetime media table contextmenu paste code'
                ]
            });

这是我的html部分,我在编辑器中显示已存储的数据库内容。

                                        <div id="day_wrapper" class="col-sm-10"> {{--parent div holder--}}
                                        <div id="limitDescErrorMessage"></div>
                                        <?php $i = 1; ?>
                                        @forelse($tour->itenaries as $key=>$day)
                                            <div class="holder-itenary">
                                                <a href="#" class="remove-itenary"><i
                                                            class="fa fa-trash pull-right"></i></a>
                                                <label class="control-label"
                                                       style="font-size: large">Day {{$i}}</label>
                                                <textarea rows="2" cols="50" name="descriptions[]"
                                                          class="form-control"
                                                          id="tinyContent">{{$day->desc}}</textarea>
                                            </div>
                                            <?php $i++ ?>
                                        @empty
                                            <div><p>No Itenaries Available</p></div>
                                        @endforelse
                                        @if($errors->first('descriptions'))
                                            <div class="alert alert-danger">{{$errors->first('descriptions')}}</div>
                                        @endif
                                    </div>

我试图寻找解决方案,但无法弄清楚......

0 个答案:

没有答案