简体   繁体   中英

JavaScript do not escape \ character?

I'm building a query for YQL, and I've ran into a dumb issue. I wont be pasting in the entire query as there is no need, just the part I'm having the issue with:

var query = encodeURI("... and xpath='//div[@class=\\'body bodySign\\']/p' ...")';

As you may notice, I've added two \\ characters, it is need for the actual query. I'm using multi queries, and I need to double esacpe the ' character in order for them to parse correctly inside YQL.

But JavaScript escapes the \\ character. It doesn't matter how many \\ I add (to "escape" to following \\ character) I still get left with only one \\ in my query.

How do I keep multiple \\ characters without them escaping each other?

Thanks

It should be

var query = encodeURI("... and xpath='//div[@class=\\\\'body bodySign\\\\']/p' ...")';

For example, hit F12 and look at the output of console.log("\\\\\\\\") .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM