需要通过 jQuery 在字符串中发送两种引号

发布于 2024-09-29 18:37:50 字数 215 浏览 0 评论 0原文

我通过 jQuery 发送一些 html,在这个 html 中有各种需要引用的值,在一个实例中,有一个嵌套值,所以我必须能够发送两种引号。这是一些模拟代码:

var myVar = "<tag value='foo' value2="config={'bar':null, 'foo2':true}" />";

如何确保双引号正确发送?

I'm sending some html via jQuery, and in this html are various values that need to be quoted, and in one instance, there's a nested value, so I have to be able to send both kinds of quotes. Here's some mock code:

var myVar = "<tag value='foo' value2="config={'bar':null, 'foo2':true}" />";

How can in ensure that the double quotes are sent properly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九命猫 2024-10-06 18:37:50

你可以逃脱他们。

var myVar = "<tag value='foo' value2=\"config={'bar':null, 'foo2':true}\" />";

You can escape them.

var myVar = "<tag value='foo' value2=\"config={'bar':null, 'foo2':true}\" />";
影子的影子 2024-10-06 18:37:50

您可以通过在字符串前面添加斜杠来转义字符串内的双引号。

像这样

"some text \" more text"

you can escape the double quotes inside the string, by adding a slash in front of it.

like this

"some text \" more text"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文