Javascript可以';一旦调用了编辑器实例,就不能更改textarea中的文本

Javascript可以';一旦调用了编辑器实例,就不能更改textarea中的文本,javascript,html,ckeditor,Javascript,Html,Ckeditor,我首先编写了一个Javascrip函数,它可以根据您在下拉框中所做的选择来更改textarea中的文本,这是一件非常简单的事情 HTML <form name="formconteudo"> <select name="selectpage" onChange="change();"> <option value="1">something</option> <option value="2">another thing</opt

我首先编写了一个Javascrip函数,它可以根据您在下拉框中所做的选择来更改
textarea
中的文本,这是一件非常简单的事情

HTML

<form name="formconteudo">
<select name="selectpage" onChange="change();">
<option value="1">something</option>
<option value="2">another thing</option>
<option value="3">going crazy</option>
</select>
</form>
这非常有效,并更改了textarea中的文本。但是后来我在那个textarea上调用了一个CKeditor实例,这样我就可以在那个textarea上使用CKeditor了。该编辑器加载良好,工作出色。但是现在javascript不起作用了

关于这个问题有什么提示吗


谢谢

您需要使用编辑器上的
setData
方法

在这里

CKEDITOR.instances.editor1.setData(“这是编辑器数据。

”);
这意味着您的代码将如下所示:

var Code = new Array("", "Selected 1", "Selected 2", "Selected 3");
function change()
{
var ID =  formconteudo.selectpage.options[formconteudo.selectpage.selectedIndex].value;
CKEDITOR.instances.editor1.setData( '<p>' + Code[ID] + '</p>' );
}
var code=新数组(“,”选定1“,”选定2“,”选定3”);
函数更改()
{
变量ID=formconteudo.selectpage.options[formconteudo.selectpage.selectedIndex].value;
CKEDITOR.instances.editor1.setData(“”+代码[ID]+”

); }

注意
实例。editor1
可能不会引用您的框,因此请务必使用正确的名称

我在这个问题上花了好几天时间,每个人都不断给我奇怪的解决方案。检查了他们的API,它甚至给出了一个例子

其中,
“YOUREDITORID”
是要使用的CKeditor文本区域的ID

希望这有帮助

CKEDITOR.instances.editor1.setData( '<p>This is the editor data.</p>' );
var Code = new Array("", "Selected 1", "Selected 2", "Selected 3");
function change()
{
var ID =  formconteudo.selectpage.options[formconteudo.selectpage.selectedIndex].value;
CKEDITOR.instances.editor1.setData( '<p>' + Code[ID] + '</p>' );
}
    CKEDITOR.instances.YOUREDITORID.updateElement();
    alert( document.getElementById( 'YOUREDITORID' ).value );  // The current editor data.