当我尝试粘贴 HTML 文本文件时,我总是被踢出 shell。如何才能做到这一点?我首先需要使用一些 javascript 对其进行编码吗?
例子:
db.test.insert({x:"<div id='product-description'><p>Who hasn’t wished for a mini-Roomba to handle the arduous task of cleaning their iPhone screen? Now your dreams have come true!</p> <p>See the Takara web page for a <a href='http://www.takaratomy.co.jp/products/automee/' title='automee s' target='_blank'>demo video.</a></p>
<p><strong>Colors: </strong> White, Red, Orange and Blue<br>
Runs on a single AA battery.</p>
<p>1,575 yen</p><!-- end #product-description --></div>"})
编辑
我在我的 html 中只放了单引号,并将整个内容用双引号括起来,但还是不行。外壳错误:
> j = ({z:"<div id='product-description'><p>Who hasn
---
Unicode text could not be correctly displayed.
Please change your console font to a Unicode font (e.g. Lucida Console).
---
’
bye
最佳答案
您需要删除或编码字符串中的控制字符。
例如,将您的文本粘贴到 here 中,然后编码为 UTF-8 ECMAScript(即 javascript 字符串)。
ps:这里有一篇关于 javascript 中的字符串的文章。告诉你什么需要转义。 http://docstore.mik.ua/orelly/webprog/jscript/ch03_02.htm
关于javascript - 如何将 HTML 插入 Mongodb?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15275599/