一旦调用 CKeditor 实例,Javascript 就无法更改文本区域中的文本

发布于 2024-08-17 13:32:33 字数 844 浏览 1 评论 0原文

好吧,我首先编写了一个 JavaScript 函数,它会根据您在下拉框中所做的选择来更改 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>

JS

var Code = new Array("", "Selected 1", "Selected 2", "Selected 3");
function change()
{
var ID =  formconteudo.selectpage.options[formconteudo.selectpage.selectedIndex].value;
document.formconteudo.ckeditor.value = Code[ID];
}

这非常有效,并且更改了文本区域中的文本。但后来我在该文本区域上调用了 CKeditor 实例,以便我可以在该文本区域上使用 CKEditor。编辑器加载良好且运行良好。但现在 JavaScript 不工作了。

有关问题的任何提示吗?

谢谢

Well i first wrote a Javascrip function that would change the text in a textarea according to the selection you made in a dropdown box, a really simple thing.

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>

JS

var Code = new Array("", "Selected 1", "Selected 2", "Selected 3");
function change()
{
var ID =  formconteudo.selectpage.options[formconteudo.selectpage.selectedIndex].value;
document.formconteudo.ckeditor.value = Code[ID];
}

This worked pretty good and changed the text in the textarea. But then i called a CKeditor Instance on that textarea, so that i can use the CKEditor on that textarea. The Editor loads well and works great. But now the javascript isn't working.

Any hint on the problem?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猥︴琐丶欲为 2024-08-24 13:32:33

您将需要在编辑器上使用 setData 方法。

这里是他们文档中的示例

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>' );
}

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

You are going to want to use the setData method on the editor.

Here is the example from their docs.

CKEDITOR.instances.editor1.setData( '<p>This is the editor data.</p>' );

Which means your code will look something like this:

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>' );
}

Note instances.editor1 may not refer to your box, so be sure to use the right name

怕倦 2024-08-24 13:32:33

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

http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor .html#setData

    CKEDITOR.instances.YOUREDITORID.updateElement();
    alert( document.getElementById( 'YOUREDITORID' ).value );  // The current editor data.

其中'YOUREDITORID'是CKeditor要使用的文本区域的ID。

希望这有帮助!

I've spent days on this issue, every one kept giving me odd solutions. Checked their API, and it even gives an example.

http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#setData

    CKEDITOR.instances.YOUREDITORID.updateElement();
    alert( document.getElementById( 'YOUREDITORID' ).value );  // The current editor data.

Where 'YOUREDITORID' is the ID of the textarea for CKeditor to be used.

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文