2012-09-07 42 views
0

我想刪除用戶粘貼到ckeditor時的內容格式。我試過這段代碼,但它不起作用。請幫我刪除粘貼事件中的內容

CKEDITOR.on('instanceReady', function (e) { 
    editor = e.editor; 
    editor.on('paste', function (e) { 
     editor.focus(); 
     editor.document.$.execCommand('SelectAll', false, null); 
     editor.execCommand('RemoveFormat', editor.getSelection().getNative()); 
     editor.insertHtml('additional content'); 
    }); 
}); 

回答

0

我解決我的問題,通過格式化的內容設置前值textarea的

CKEDITOR.on('instanceReady', function(e){ 
    var editor = e.editor; 
    editor.on('paste', function(e){ 
     setTimeout(function(){ 
      $('body').append("<div id='tmpCt'>"+ editor.getData() +"</div>"); 
      $('#tmpCt div, #tmpCt p, #tmpCt a, #tmpCt span').removeAttr("style"); 
      $('#requiredDescription').val($('#tmpCt').html()); 
      $('#tmpCt').remove(); 
     }, 100); 
    }); 
}); 
1

嘗試增加CKEDITOR.config.forcePasteAsPlainText= true;到config.js,應該解決您的問題。

+0

forcePasteAsPlainText剝離a,ul,ol,li ...(僅舉幾個例子),而RemoveFormatting函數則沒有。 – whitehat101