1

HTMLコードには複数のテキストエリアがあるため、JavaScriptを介してid値を渡し、各テキストエリアのデータを取得します。ただし、JS関数では、「CKEDITOR.instances.id」がCKEDITOR.instances.editor_1、CKEDITOR.instances.editor_2、CKEDITOR.instances.editor_4などの期待どおりに表現されていないため、何もありません。取得したデータ。誰でもこれを修正する方法を知っています。私に聞かせてください。感謝の山。

HTMLコード:

    <textarea name="edit_1"></textarea>
    <input type="button" value="submit" onClick="getValue('edit_1')" />
    <textarea name="edit_2"></textarea>
    <input type="button" value="submit" onClick="getValue('edit_2')" />
    <textarea name="edit_2"></textarea>
    <input type="button" value="submit" onClick="getValue('edit_3')" />

JSコード:

    var getValue = function(id) {
        var content = CKEDITOR.instances.id.getData();
        alert(content);
    };
4

2 に答える 2

8

idの間に[]を追加してみてください

var getValue = function(id) {
    var content = CKEDITOR.instances[id].getData();
    alert(content);
};
于 2013-02-04T14:38:46.887 に答える
0

イベントを複数のインスタンスを持つアクションにバインドしていたので、このようなことをしなければなりませんでした。データを取得しようとしましたが、最後のデータ以外は常にnullを返します...イベント(e.editor)を使用しても機能しました。

var editors = CKEDITOR.instances;
    for (var x in editors) {
      if (editors[x]) {
        var thisName = editors[x].name;
        if (editors[thisName]) {
          editors[thisName].on('focus', function (e) {
            socket.emit('ckeditor_field_type_edit', user, e.editor.name);
          });
          editors[thisName].on('key', function (e) {
            var data = e.editor.getData();
            socket.emit('ckeditor_field_type_typing', user, e.editor.name, data);
          });
          editors[thisName].on('blur', function (e) {
            var data = e.editor.getData();
            setTimeout(function () {
              socket.emit('ckeditor_field_type_edit_finish', user, e.editor.name, data);
            }, 1000);
          });
        }
      }
    }
于 2018-09-21T06:01:47.400 に答える