2012-12-24 39 views
0

我正在使用MVC3 CKeditor,我需要在CKeditor中插入一些額外的數據,當我點擊提交按鈕時。我怎樣才能做到這一點?我的代碼到目前爲止如下:這是我的HTML頁面如何使用jquery向ckeditor添加額外的數據?

 <div id="div-child-Cat-Desc-Long" class="CKEditor-child-DIV"> 
        @Html.TextAreaFor(m => m.Message, new { Class = "input-xlarge", @id = "txtAreasocial",@rows="3" }) 
       </div> 

$(document).ready(function() { 
    //Passing the Text Area reference to get the CK Editor 
    var editor = CKEDITOR.editor.replace('txtAreasocial'); 
}); 

$('#btnadd').click(function() { 
    alert('hi'); 

    var data = "Hello. This is a new node."; 
    alert(data); 
    CKEDITOR.editor.setData(data); 

    editor.setData(data) 
}); 
+0

額外的數據意味着..什麼?你到底想要什麼? – rash111

+0

extradata意味着我會得到選定的複選框的價值像產品 和類似的類型我需要將它添加到ckeditor –

回答

1

我不太確定CKeditor有多少實例,你有。您需要獲取編輯器的實例並使用setData方法將數據添加到特定實例。例如:

CKEDITOR.instances['editor1'].setData(data) 

CKEDITOR.instances.editor1.setData(data) 

檢查setData方法在documentation

+0

我曾嘗試,但它不工作tahnk ypu爲我的回覆更多的幫助請 –

+0

你得到警報 - >點擊解僱? – Amyth

+0

是的,我得到了警報但數據沒有添加到ckeditor –

0
  • 做出新的子元素

    var txtNode = document.createTextNode("Hello. This is a new node."); 
    
  • 然後附加到您的編輯..

    txtNode.appendTo($('#editor')); 
    
+0

我曾嘗試過,但它沒有工作tahnk ypu爲我的回覆更多的幫助請 –

1

使用 「insertHtml」 或 「insertText」 功能將數據附加到CKEDITOR中。就像這樣:

CKEDITOR.instances['input-text-area-ID'].insertHtml(data); 
相關問題