HTML代码一直显示在我的网页上



my
等显示在网页上。通过函数传递的输入将创建/分割为行和节,如下所示:

[
'If you can talk with crowds and keep your virtue,',
'Or walk with Kings—nor lose the common touch,',
'If neither foes nor loving friends can hurt you,',
'If all men count with you, but none too much;',
'If you can fill the unforgiving minute',
'With sixty seconds’ worth of distance run,',
'Yours is the Earth and everything that’s in it,',
'And—which is more—you’ll be a Man, my son!'
]

我用来插入必要的换行符的函数如下所示:

function formatPoem(poem) {
const stanzas = poem.map((stanza) => {
console.log(stanza)
const lines = stanza.map(line => `${line}`)
return lines.join("r");
});

return stanzas.join("<br>");
}

我正在使用node.js和js。有人能帮我一下吗?

我希望这首诗能反映诗的结构,而不显示HTML代码

如果你不想使用Express,你需要使用class: http.Server.

var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('Hello World!');
res.end();
}).listen(8080);

相关内容

  • 没有找到相关文章

最新更新