cleditorのドキュメントには、「keyup」イベントで機能すると主張する「change」イベントがあると記載されていますが、残念ながら、私のテストではFirefox 7では期待どおりに機能しませんでした(テキストエディタをクリックする必要があります) 。
Jsfiddle: http: //jsfiddle.net/qm4G6/27/
コード:
var cledit = $("#input").cleditor()[0];
cledit.change(function(){
var v = this.$area.context.value;
$('#x').html(v);
});
同じことについて尋ねた別のStackOverflowの質問もあります。この質問では、ユーザーLingがプラグインを変更して独自の関数を追加することを提案しています
。jqueryCLEditorからコンテンツを取得する
編集:上記のSO質問結果が機能しないというコメントに基づいて、以下のコードを修正しました。これは、IE9およびIE9の「IE8」開発者モードで機能します。http://jsfiddle.net/qm4G6/80/
$(document).ready(function(){
var cledit = $("#inputcledit").cleditor()[0];
$(cledit.$frame[0]).attr("id","cleditCool");
var cleditFrame;
if(!document.frames)
{
cleditFrame = $("#cleditCool")[0].contentWindow.document;
}
else
{
cleditFrame = document.frames["cleditCool"].document;
}
$( cleditFrame ).bind('keyup', function(){
var v = $(this).text();
$('#x').html(v);
});
});
別の編集:HTMLを取得するには、iframe内でのような本文を見つける必要があります$(this).find("body").html()
。以下のコードを参照してください。JSFiddle: http: //jsfiddle.net/qm4G6/84/
var cledit = $("#inputcledit").cleditor()[0];
$(cledit.$frame[0]).attr("id","cleditCool");
var cleditFrame;
if(!document.frames)
{
cleditFrame = $("#cleditCool")[0].contentWindow.document;
}
else
{
cleditFrame = document.frames["cleditCool"].document;
}
$( cleditFrame ).bind('keyup', function(){
var v = $(this).find("body").html();
$('#x').html(v);
});
$("div.cleditorToolbar, .cleditorPopup div").bind("click",function(){
var v = $( cleditFrame ).find("body").html();
$('#x').html(v);
});