我的 sails 应用程序中有一个 ejs 文件,如下所示
<a href='/<%= viewname %>?where={"name":"<%= profile.pname %>"}'>
这适用于大多数名称,但其中包含撇号的名称除外。本质上,EJS 将撇号解析为单引号,这会关闭 href 并使我传递的名称不正确
http://localhost:1337/myviewnamwe?where={"name":"tom
它应该在哪里
http://localhost:1337/myviewnamwe?where={"name":"tom's diner}
最佳答案
我会在关键部分使用 URL 编码:{"name":"<%= profile.pname %>"}
更多信息:
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/uri/rdoc/URI/Escape.html http://www.w3schools.com/tags/ref_urlencode.asp
关于node.js - 如何在 ejs 中转义变量名中的撇号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23155059/