Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将CKEditor与ExpressJS一起使用时,浏览器中会显示HTML标记_Javascript_Node.js_Forms_Express_Ckeditor - Fatal编程技术网

Javascript 将CKEditor与ExpressJS一起使用时,浏览器中会显示HTML标记

Javascript 将CKEditor与ExpressJS一起使用时,浏览器中会显示HTML标记,javascript,node.js,forms,express,ckeditor,Javascript,Node.js,Forms,Express,Ckeditor,这是我的app.js文件 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge">

这是我的app.js文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link href="/css/style.css" rel="stylesheet" type="text/css">
    <script src="https://cdn.ckeditor.com/4.10.0/standard/ckeditor.js"></script>
    <title>Jo Blog</title>
</head>
<body>

    {{{body}}}
    <script type="text/javascript" src="/js/ckeditor/ckeditor.js"></script>
    <script type="text/javascript" src="/js/ckeditor/adapters/jquery.js"></script>
    <script type="text/javascript">   
       // CKEDITOR.config.enterMode = CKEDITOR.ENTER_BR;

        CKEDITOR.replace('content', {
            plugins: 'wysiwygarea , toolbar, basicstyles, link',
            enterMode: CKEDITOR.ENTER_BR,
            autoparagraph: false,
            uiColor: '#AADC6E',
            removePlugins: 'elementspath'
        });

    </script>

</body>
</html>

Jo博客
{{{body}}}
//CKEDITOR.config.enterMode=CKEDITOR.ENTER\u BR;
CKEDITOR.replace('content'{
插件:“所见即所得,工具栏,基本样式,链接”,
输入模式:CKEDITOR.ENTER\u BR,
自动参数:错误,
uiColor:“#AADC6E”,
移除插件:“elementspath”
});
这是我希望它能影响的形式——新的把手

<h1>New Blog</h1>

<form method="post" action="/blog">
    <label>Title</label><br>
    <input type="text" name="title"/><br>
    <label>Blog Content</label><br>
    <textarea name="content" id="ckEdit"></textarea><br>

    <input type="submit" name="submit">

</form>
新博客
标题

博客内容

现在编辑器显示得很好,我可以在其中编写,但是当我点击submit时,HTML标记仍然都在那里,例如“Hello World”


我已经用谷歌搜索出了这个问题的答案,阅读了我在这里能找到的关于它的所有内容,并尝试了我读过的所有内容,但没有任何效果:/Any ideas???

我让你的代码提交表单内容和标题,而不在浏览器中显示html标记

文件ckeditor.js从两个源加载两次,一次由cdn加载到头部,另一次加载到正文它们可能相互冲突。我在正文中注释掉了脚本,并在头部保留了cdn.ckeditor[…]ckeditor.js脚本

出于测试目的,我删除了手柄{{{body}}},并将表单直接插入html文件

我怀疑问题出在表单的action“/blog”中,但为了查看返回的结果,我将表单的action更改为“form.php”(包含在下面)。php文件只是将提交的内容发送回浏览器。它确实会在浏览器中正确显示提交的内容和标题

下面是“form.php”和修改后的html文件

希望这对解决问题有点帮助

form.php

<?php

$title = $_POST['title'];
$content = $_POST['content'];

print <<< PRINT
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>$title</title>
</head>

<body>
$content
</body>

</html>
PRINT;

?>

HTML文件

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <!--<link href="/css/style.css" rel="stylesheet" type="text/css">-->
  <script src="https://cdn.ckeditor.com/4.10.0/standard/ckeditor.js"></script>
  <title>Jo Blog</title>
</head>

<body>
  <!-- changed the form's action from /blog to form.php for demo purposes -->
  <form method="post" action="form.php">
    <label>Title</label><br>
    <input type="text" name="title"/><br>
    <label>Blog Content</label><br>
    <textarea name="content" id="ckEdit"></textarea><br>
    <input type="submit" name="submit">
  </form>

  <!--
   <script type="text/javascript" src="/js/ckeditor/ckeditor.js"></script>
   <script type="text/javascript" src="/js/ckeditor/adapters/jquery.js"></script>
  -->

  <script type="text/javascript">   
  // CKEDITOR.config.enterMode = CKEDITOR.ENTER_BR;

  CKEDITOR.replace('content', {
   plugins: 'wysiwygarea , toolbar, basicstyles, link',
   enterMode: CKEDITOR.ENTER_BR,
   autoparagraph: false,
   uiColor: '#AADC6E',
   removePlugins: 'elementspath'
  });

  </script>

</body>
</html>

Jo博客
标题

博客内容

//CKEDITOR.config.enterMode=CKEDITOR.ENTER\u BR; CKEDITOR.replace('content'{ 插件:“所见即所得,工具栏,基本样式,链接”, 输入模式:CKEDITOR.ENTER\u BR, 自动参数:错误, uiColor:“#AADC6E”, 移除插件:“elementspath” });
CKEditor在获取格式化文本的值时会像在编辑器中一样对HTML进行mantains处理,那么,问题出在哪里?你想剥离所有HTML,只获取文本?@MatheusGomes我希望HTML标记也在那里,但实际上不会显示在浏览器中。在我写东西的时候,前端会显示标签。我希望标签在那里,但前端看不见,所以“hello world

”应该被视为“hello world”,也许你想要的是用提供的代码编辑源代码,而你所说的,我能推断的唯一一件事是你正在以文本模式编写HTML,因此,您无法进行渲染,因为CKEditor使用字符引用转义HTML特殊字符,如“”(分别变成“”和“”)@MatheusGomes我没有在HTML标记中编写。它们由ckeditor自动生成。我首先使用的是ckeditor,这样我就可以在用户的输入中生成所见即所得的外观。它们在写入时不会显示,但当它保存到数据库中,然后在浏览器中呈现时,标记会在丢失实际格式的同时显示出来哦,哇,谢谢!!我以前从未使用过PHP,是什么让你这么想的?太好了。希望这有帮助。我使用php只是因为它似乎是最简单的测试方法。当心!