在 JavaScript/HTML 中嵌套引号
如何在 HTML 中嵌套超出第二层的引号?据我所知,只有两种类型的引号 - 单引号(')和双引号(")。我知道使用斜杠转义 - 你必须在代码中转义,但转义在浏览器级别不起作用绕过以下
<p onclick="exampleFunc('<div id="divId"></div>');">Some Text</p>
代码的
可接受方法是什么?');">一些文本
How do you nest quotes in HTML beyond the second level? As far as I know, there are only 2 types of quotes - single(') and double("). I am aware of escaping using slashes - you have to escape in the code but that escaping won't work at the browser level. What is the accepted method to get around something like the following?
<p onclick="exampleFunc('<div id="divId"></div>');">Some Text</p>
That code prints to the browser:
');">Some Text
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要使用正确的转义/编码。在 HTML 中使用字符引用:
或者在 JavaScript 中使用字符串转义序列:
You need to use proper escaping/encoding. Either in HTML using character references:
Or in JavaScript using string escape sequences:
编辑:这不是 HTML 中 JavaScript 的解决方案,而是仅适用于 JavaScript。我的错...
链接。这是“递归转义”。
Edit: this is not a solution for JavaScript in HTML, but for JavaScript only. My bad...
Link. It's "recursive escaping".
您需要使用 \ 转义字符,
因此您的代码应该类似于
以下内容: 特殊字符
you need to escape the characters using the \
so your code should look like
Here is some info on Special Characters