开发者

Need to send two kinds of quotes in a string via jQuery

开发者 https://www.devze.com 2023-01-22 23:53 出处:网络
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

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 开发者_JS百科that the double quotes are sent properly?


You can escape them.

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


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

like this

"some text \" more text"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号