如何使javascript忽略(\)字符? [英] How to make javascript ignore escape ( \ ) character?

查看:119
本文介绍了如何使javascript忽略(\)字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

qAnswersR[90430] = [];
    qAnswersR[90430].push("[math]k: \frac{(x+20)^{2}}{256}+\frac{(y-15)^{2}}{81}=1[/math]");

我需要将值变成变量,但是当我将console.log出来像这样的数组:

And I need to get the value into variable, but when I console.log out the array like this:

console.log(qAnswersR[90430]);

我得到: [math] k:rac {(x + 20)^ {2}} {256} + rac {(y-15)^ {2}} {81} = 1 [/ math],[数学] k:81(x + 20)^ {2} 256(y-15)^ {2} = 20736 [/ math]

I get: [math]k: rac{(x+20)^{2}}{256}+rac{(y-15)^{2}}{81}=1[/math],[math]k: 81(x+20)^{2}+256(y-15)^{2}=20736[/math]

但转义标记\消失,但我需要它,我该怎么办?

But the escape tag "\" disappears, but I need it there, what should I do?

推荐答案


但转义标记\消失,但我需要它,我该怎么办?

But the escape tag "\" disappears, but I need it there, what should I do?

您需要转义反斜杠,即使用 \\ 而不是 \

You need to escape the backslash, i.e., use \\ instead of just \:

"[math]k: \\frac{(x+20)^{2}}{256}+\\frac{(y-15)^{2}}{81}=1[/math]"
          ^                       ^

这篇关于如何使javascript忽略(\)字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆