10

textareaさて、私は最初に、ドロップダウンボックスで行った選択に応じてテキストを変更するJavascrip関数を作成しました。これは非常に簡単なことです。

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];
}

これはかなりうまく機能し、textareaのテキストを変更しました。しかし、そのテキストエリアでCKeditorインスタンスを呼び出したので、そのテキストエリアでCKEditorを使用できます。エディターはうまくロードされ、うまく機能します。しかし、現在、javascriptは機能していません。

問題に関するヒントはありますか?

ありがとう

4

2 に答える 2

26

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してください、それで正しい名前を使うことを忘れないでください

于 2010-01-10T22:26:09.823 に答える
2

私はこの問題に何日も費やしました、誰もが私に奇妙な解決策を与え続けました。彼らの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はどこにありますか。

お役に立てれば!

于 2011-11-20T19:31:34.813 に答える