CKeditor具有多种动态文本区域 [英] CKeditor with multible dynamic textareas

查看:193
本文介绍了CKeditor具有多种动态文本区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,可以提交多个步骤。当用户单击添加步骤时,将显示另一个文本区域。我使用CKeditor。它工作伟大的第一次迭代,但在所有后续的,它显示一个标准的文本区域。这是我的代码:

I have a forms which allows multiple steps to be submitted. When a user clicks "add step" another textarea appears. I am using CKeditor. It works great of the first iteration, but on all subsequent ones, it shows a standard text area. Here is my code:

<form method="post" action="process_project.php">
<b>Steps for your project:</b>
<div>&nbsp;</div>
Step 1
<div id="divWho">
<textarea name="projSteps[]" class="steps" id="1" rows="10" cols="60"></textarea> 
</div>
<div>&nbsp;</div>
<input type="button" value="Add project step" onClick="addTextArea();">
<input type="submit" name="submit" value="submit" />
</form>


<script type="text/javascript">
var counter = 1;
var limit = 11;
function addTextArea() {
if (counter == limit-1) {
alert("You have reached the limit of adding " + counter + " project steps");
return false;
}
else {
var newdiv = document.createElement('div');
newdiv.innerHTML = "Step " + (counter + 1) + " <br><textarea name='projSteps[]' id=counter rows='10' cols='60'>";
document.getElementById('divWho').appendChild(newdiv);
counter++
return true;
}
}
</script>
<script> CKEDITOR.replace('1');</script>

如何使每个新的动态创建的文本区域也使用CKeditor?我一直在这个工作了几个小时,我被解雇。

How can I make each new dynamically created text areas also use CKeditor? I have been working on this for hours and I am stumped.

推荐答案

我想你需要移动CKEDITOR.replace('1');

I think you need to move CKEDITOR.replace('1'); inside the addTextArea() method enclosed in the else block before the return statement.

并且如果你将replace参数硬编码为'1',它只会转换第一个textarea的实例,id为1到CKEditor,忽略其他。动态生成Id并将其传递给repalce方法。如下所示:

And also if you hard code the replace parameter to '1', it will only convert the first instance of textarea with id 1 to CKEditor and ignore others. Generate an Id dynamically and pass it to repalce method. Something like below,

var step = 'step'+counter; 

div = <textarea name='projSteps[]' id=step rows='10' cols='60'>; 

CKEDITOR.replace(step);

我没有完全编写第二步,我想你可以根据需要修改它。

I haven't written the second step completely, I guess you can modify it as you need.

我正在使用类似的功能,这种方法适用于我。

I'm working on a similar functionality and this approach works for me.

这篇关于CKeditor具有多种动态文本区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆