2016-08-31 8 views
0

したがって、基本的には<textarea>がない場合でもリッチテキストボックスを作成したいと思います。私はrichtextboxを自分自身に追加したい。ではないtinyMCE。問題は、これを追加した後、私は小さなMCEイベントがないことだと思います。どのようなものであるか、私が考えているTinyMCE:tinyMCE.init()はまだ追加されていません<textarea>

...

$("<textarea></textarea>").tinyMCE({options})が、これは、リッチテキストボックスのHTML文字列を返します。そうすれば、自分自身でhtml文字列を追加できます。注目すべきことに、特にイベントを完全に処理するはずです。

これも可能ですか?

答えて

0

javascriptで<textarea>を作成し、それを画面に表示する直前にDOMに追加することができます。ただし、テキストエリアにはidを使用する必要があります。

//an editor id needs to be used in this method 
var editorId = "#myId"; 
var options = { 
    //options 

} 
//Creates an editor instance and adds it to the EditorManager collection. 
tinyMCE.createEditor(editorId, options); 

//get the editor instance by its id 
var editor = tinyMCE.get(editorId); 

//get the root element you want insert the editor into. (E.g. body element) 
var root = document.getElementsByTagName('body')[0]; 

//create a textarea element 
var textarea = document.createElement("textarea"); 
//set its id 
textarea.setAttribute("id", editorId); 
//append it to the root element 
root.appendChild(textarea); 

//register your events 
registerEvents(editor); 

//display editor on screen 
editor.render(); 
//set content of editor 
editor.setContent("<h1>Hello World!</h1><p>Hello World!</p>"); 

//retrieve content from editor 
var htmlContent = editor.getContent(); 

console.log(htmlContent); 

function registerEvents(editor) { 
    editor.on("init", function(e) { 
    console.log("Init", e); 
    }); 

    editor.on("focus", function(e){ 
    console.log("Focus", e); 
    }); 

    editor.on("blur", function(e){ 
    console.log("Blur", e); 
    }); 
} 

JSFiddleの例を示します。