Html 多个tinymce textareas
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15509484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
multiple tinymce textareas
提问by Udo
I use tinymce for a webpage that dynamically generates at least 5 texts.
The configuration I use only works on the first textarea
unfortunately.
我将 tinymce 用于动态生成至少 5 个文本的网页。不幸的是,
我使用的配置仅适用于第一个textarea
。
tinyMCE.init({
height : "300",
mode : "exact",
elements : "content",
theme : "simple",
editor_selector : "mceEditor",
...
<textarea class="mceEditor" name="content" rows="15" cols="40">content</textarea>
What's the configuration to enable tinymce editing in alltextarea
's.
什么是使TinyMCE用于编辑配置所有textarea
的。
回答by DustyWall
If you're using "exact" mode you'll need to specify the ids of the elements you wish to convert to editors.
如果您使用“精确”模式,则需要指定要转换为编辑器的元素的 ID。
function initMCEexact(e){
tinyMCE.init({
mode : "exact",
elements : e,
...
});
}
// add textarea element with id="content" to document
initMCEexact("content");
// add textarea element with id="content2" to document
initMCEexact("content2");
// add textarea element with id="content3" to document
initMCEexact("content3");
Or, you can use the "textarea" mode, which indiscriminately applies the editor to all textareas.
或者,您可以使用“textarea”模式,该模式将编辑器不加选择地应用于所有文本区域。
function initMCEall(){
tinyMCE.init({
mode : "textareas",
...
});
}
// add all textarea elements to document
initMCEall();
Just remember that if you're creating textareas dynamically, you will need to call tinyMCE.init() aftercreating the elements, because they need to be existing for tinyMCE to be able to convert them.
请记住,如果您正在动态创建文本区域,则需要在创建元素后调用 tinyMCE.init() ,因为它们需要存在以便 tinyMCE 能够转换它们。
回答by Alex Vazhev
For TinyMCE 4.0 you have to use a selector or defining a tinymce.init object/method for each desired configuration (https://www.tinymce.com/docs/get-started/multiple-editors/).
对于 TinyMCE 4.0,您必须使用选择器或为每个所需的配置定义一个 tinymce.init 对象/方法(https://www.tinymce.com/docs/get-started/multiple-editors/)。
For example, this is a page with 3 editors:
例如,这是一个有 3 个编辑器的页面:
<!DOCTYPE html>
<html>
<head>
<script src="http://cdn.tinymce.com/4/tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
selector: '#myeditable-h1',
toolbar: 'undo redo'
});
tinymce.init({
selector: '.standard-editor'
});
</script>
</head>
<body>
<form method="post">
<h1 id="myeditable-h1">This Title Can Be Edited If You Click Here</h1>
</form>
<form method="post">
<div id="myeditable-div1" class="standard-editor">
<p>This section1 of content can be edited...</p>
</div>
<div id="myeditable-div2" class="standard-editor">
<p>This section2 of content can be edited...</p>
</div>
</form>
</body>
</html>
回答by Elena Slavcheva
You should use different mode in your configuration. For example mode: "specific_textareas" to work for all textarea with a given class which is specified in the editor_selector parameter.
您应该在配置中使用不同的模式。例如模式:“specific_textareas”适用于具有在 editor_selector 参数中指定的给定类的所有文本区域。
In order to work on all textareas with class mceEditor you can use this:
为了使用类 mceEditor 处理所有文本区域,您可以使用以下命令:
tinyMCE.init({
mode : "specific_textareas",
editor_selector : "mceEditor",
.....
回答by Omid Ahmadyani
use class in selector i have two or more textarea that i want init those with tiny int so
在选择器中使用类我有两个或多个 textarea,我想用 tiny int 初始化那些
<textarea class="mytextarea"></textarea>
<textarea class="mytextarea"></textarea>
.
.
.
in init tinyint code:
在 init tinyint 代码中:
tinymce.init({
selector: 'textarea.mytextarea',
plugins : 'advlist autolink link lists preview table code pagebreak',
.
.
.
回答by Dan Ullom
According to tinymce.com/wiki.php/Configuration:selector, selector is the recommended way of selecting what elements should be editable.
根据tinymce.com/wiki.php/Configuration:selector,选择器是选择哪些元素应该可编辑的推荐方式。
For all textarea elements, as requested:
对于所有 textarea 元素,根据要求:
selector: "textarea",
Or more elegantly, only those elements with a specific CSS tag:
或者更优雅地,只有那些具有特定 CSS 标签的元素:
selector: "textarea.editme",
<textarea class="editme">