我不确定 CKEditor 是否允许您想要的行为。我建议调查猛禽编辑器 - http://www.raptor-editor.com/
我已经整理了一个示例,说明如何使用选项实例化 Raptor,以确保编辑器不会尝试修复无效的 HTML - JSFiddle。
Raptor 实例化是:
<textarea id="raptor">
<table>
<tbody>$GarbagePailKids</tbody>
</table>
</textarea>
<script type="text/javascript">
$('#raptor').editor({
// Enable editor immediately
autoEnable: true,
// Replace the element with the editor
replace: true,
// Disable the cancel, save & dock buttons
disabledUi: ['cancel', 'save', 'dock'],
// Disable the unsaved edits warning, and the clean & empty element plugins, both of which will attempt to fix broken HTML
disabledPlugins: ['unsavedEditWarning', 'clean', 'emptyElement'],
// Disable the "you have unsaved edits on this page" warning triggered when one attempts to leave the page after editing
unloadWarning: false,
// Plugin specific options
plugins: {
// Docking options forcing the editor to be always docked to the textarea
dock: {
docked: true,
dockToElement: true,
persistent: false
}
}
});
</script>
无论如何,浏览器通常会尝试纠正无效的 HTML。