Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在重复的tinyMCE元素中插入文本_Php_Jquery_Laravel_Tinymce - Fatal编程技术网

Php 在重复的tinyMCE元素中插入文本

Php 在重复的tinyMCE元素中插入文本,php,jquery,laravel,tinymce,Php,Jquery,Laravel,Tinymce,我已经尝试了一段时间,试图找到一种体面的方法,使用jQuery在tinyMCE文本区域中插入和修改文本,但收效甚微。人们提供的大多数答案通常只用于单个tinyMCE文本区域,或者根据ID调用tinyMCE字段。这一切都很好,但我的项目让我在页面上动态创建重复字段,这使得获取特定tinyMCE元素变得很困难 在实现tinyMCE之前,我是通过与父div关联的类调用重复字段的 例: 上面的代码是在我通过dropbox更改产品时运行的。“$(this)”作为dropbox,它然后调用父div并找到de

我已经尝试了一段时间,试图找到一种体面的方法,使用jQuery在tinyMCE文本区域中插入和修改文本,但收效甚微。人们提供的大多数答案通常只用于单个tinyMCE文本区域,或者根据ID调用tinyMCE字段。这一切都很好,但我的项目让我在页面上动态创建重复字段,这使得获取特定tinyMCE元素变得很困难

在实现tinyMCE之前,我是通过与父div关联的类调用重复字段的

例:

上面的代码是在我通过dropbox更改产品时运行的。“$(this)”作为dropbox,它然后调用父div并找到description textarea,然后将正确的默认数据(从控制器传递)输入该字段

这里的问题是,当您初始化tinyMCE时,原始文本区域几乎被掩埋,并且使用此方法无法访问

tinyMCE站点提供了如何将文本插入tinyMCE字段的文档,但这些文档仅在页面上只有一个tinyMCE元素或您自己手动插入字段时才起作用

    // Sets the HTML contents of the activeEditor editor
    tinyMCE.activeEditor.setContent('<span>some</span> html');

    // Sets the raw contents of the activeEditor editor
    tinyMCE.activeEditor.setContent('<span>some</span> html', {format : 'raw'});

    // Sets the content of a specific editor (my_editor in this example)
    tinyMCE.get('my_editor').setContent(data);

    // Sets the bbcode contents of the activeEditor editor if the bbcode plugin was added
    tinyMCE.activeEditor.setContent('[b]some[/b] html', {format : 'bbcode'});
//设置activeEditor的HTML内容
tinyMCE.activeEditor.setContent('somehtml');
//设置activeEditor的原始内容
tinyMCE.activeEditor.setContent('somehtml',{format:'raw'});
//设置特定编辑器的内容(本例中为my_编辑器)
tinyMCE.get('my_editor').setContent(数据);
//如果添加了bbcode插件,则设置activeEditor编辑器的bbcode内容
tinyMCE.activeEditor.setContent('[b]some[/b]html',{format:'bbcode'});
有没有办法把这些东西转换成我可以用的东西?或者是否有其他方法可用于将信息插入文本区域


提前谢谢

是,当编辑器初始化时,tinymce源元素变得不可访问。这是必要的,因为tinymce创建了一个新的contenteditable iframe,然后用于编辑文本。编辑器文本在几个事件上被写回前一个文本区域

您要求使用jQuery方式来访问tinymce编辑器内容。这是可能的。 下面的示例显示如何访问编辑器主体元素,查找类为
.js description
的html元素并重置其值

var editor = tinymce.activeEditor || tinymce.get('my_editor_id') || tinymce.editors[0];
$(editor.getBody()).find(".js-description").val('new_val');

尝试了这一点,但遗憾的是tinyMCE.activeEditor返回了一个空值,这很可能是因为在我单击编辑器之前,activeEditor是空的,并且在我的java控制台中得到了一个“uncaughttypeerror:cannotcallmethod'getBody'of null”。不幸的是,我需要在pageload上进行这些更改,而无需选择活动编辑器(因为一个页面上一次可以有多个tinyMCE编辑器)。当编辑器收到用户的单击时,将设置activeEditor。查看我的最新答案
var editor = tinymce.activeEditor || tinymce.get('my_editor_id') || tinymce.editors[0];
$(editor.getBody()).find(".js-description").val('new_val');