CKEDITOR 值显示在控制台日志结果的 1 行中
CKEDITOR values show in 1 line in the console log result
我正在创建 CKeditor 函数。现在我的问题是我无法获取 CKeditor 文本区域中的值。我尝试控制台日志显示结果,它不能按照 html 显示如下图:
下面是我的编码:
<textarea id="editor1" name="editor1">This is sample text</textarea>
<script type="text/javascript">
CKEDITOR.replace( 'editor1', {
height: 300,
// enterMode: CKEDITOR.ENTER_BR,
filebrowserUploadUrl: "/eokclaim/app/ajaxfile.php?type=file",
filebrowserImageUploadUrl: "/eokclaim/app/ajaxfile.php?type=image"
} );
function updateDiv(){
var editorText = CKEDITOR.instances.editor1.getData();
console.log(editorText);
}
</script>
我希望控制台日志中的预期结果是(我希望控制台日志结果显示在 1 行中):
<p>Picture 1:</p><br /><p><img alt="" src="https://www.abc.com.my/folder/app/uploads/blue-pin.png" style="height:100px; width:100px" /></p><br /><p>Picture 2:</p><br /><p><img alt="" src="https://www.abc.com.my/folder/app/uploads/1.png" style="height:34px; width:100px" /></p>
希望有人能指导我如何解决这个问题。谢谢
为了去除换行符,可以使用replace
函数。你的代码看起来像:
function updateDiv(){
var editorText = CKEDITOR.instances.editor1.getData().replace(/(\r\n|\n|\r)/gm, "");
console.log(editorText);
}
如果 getData()
像我想的那样返回一个字符串,它应该可以工作。
我正在创建 CKeditor 函数。现在我的问题是我无法获取 CKeditor 文本区域中的值。我尝试控制台日志显示结果,它不能按照 html 显示如下图:
下面是我的编码:
<textarea id="editor1" name="editor1">This is sample text</textarea>
<script type="text/javascript">
CKEDITOR.replace( 'editor1', {
height: 300,
// enterMode: CKEDITOR.ENTER_BR,
filebrowserUploadUrl: "/eokclaim/app/ajaxfile.php?type=file",
filebrowserImageUploadUrl: "/eokclaim/app/ajaxfile.php?type=image"
} );
function updateDiv(){
var editorText = CKEDITOR.instances.editor1.getData();
console.log(editorText);
}
</script>
我希望控制台日志中的预期结果是(我希望控制台日志结果显示在 1 行中):
<p>Picture 1:</p><br /><p><img alt="" src="https://www.abc.com.my/folder/app/uploads/blue-pin.png" style="height:100px; width:100px" /></p><br /><p>Picture 2:</p><br /><p><img alt="" src="https://www.abc.com.my/folder/app/uploads/1.png" style="height:34px; width:100px" /></p>
希望有人能指导我如何解决这个问题。谢谢
为了去除换行符,可以使用replace
函数。你的代码看起来像:
function updateDiv(){
var editorText = CKEDITOR.instances.editor1.getData().replace(/(\r\n|\n|\r)/gm, "");
console.log(editorText);
}
如果 getData()
像我想的那样返回一个字符串,它应该可以工作。