CKEditor捉取、設定內容

摘要:捉取&設定CKEditor內容

有很多的人想利用CKeditor的值或是設定預設內容在裡面吧,試寫了一下,用下面的參數即可(Content是id)

捉出來的值用一般的欄位或另一個textarea也可以直接承接

CKEDITOR.instances.Content.getData();
CKEDITOR.instances.Content.setData( '<p>Some other editor data</P>')

 

<html>
<head>
<title>Strip HTML</title>

<script type="text/javascript">

String.prototype.stripHTML = function()
{
       var matchTag =/<(?:.|\s)*?>|nbsp;/g;
        // Replace the tag
        return this.replace(matchTag,"");
};
 
function ShowStrippedText()
{
        var sourceInput = CKEDITOR.instances.Content.getData();
        var destInput = document.getElementById("textDestination");
        // Set the destination text area to the value of the newly stripped HTML
destInput.value = sourceInput.stripHTML();
}
function alertckvalue()
{
CKEDITOR.instances.Content.setData( '<p>Some other editor data</P>')
alert(CKEDITOR.instances.Content.getData());
alert(document.getElementById("textDestination").value);
}
</script>
</head>
<body>

<已計算完值>
<input type="button" value="Strip HTML" onclick="ShowStrippedText()" /><br />
<input type="button" value="Set CKeditor data" onclick="alertckvalue()" /><br />

<textarea id="textDestination" rows="10" cols="80"></textarea>
</body>
</html>