\对非转义字符做什么? [英] what does \ do on non escape characters?
问题描述
我提出另一个问题,所以我会问别的。 p>
根据 http:// www .c-point.com / javascript_tutorial / special_characters.htm 有一些转义字符,如\\\
和\b。但是/不是其中之一。在这种情况下会发生什么? ( \ /
)是被忽略的 \
我有一个字符串在javascript 'http:\ / \ / www.site.com\ / user'
。不,这是一个文字,'
所以使用它会像
\\\ \\ /
无论如何我想逃避这个字符串,所以关于非特殊的转义字符发生什么的问题。
另一个问题是如果我有名称:\t我
(或名称:\\我
是否有功能来逃避它,所以有一个选项卡?我使用C#,这些字符串来自一个JSON文件
根据Mozilla :
对于未列出的字符[...],前面的反斜杠将被忽略,但此用法已弃用,
应为避免。
https://developer.mozilla.org/en/JavaScript/Guide/Values%2c_Variables%2c_and_Literals#section_19
\ /
序列未列出,但至少有两个常用的用法:
< 1>需要使用正则表达式中的文字斜杠使用 / foo /
语法:
var re = / ^ http:\ / \ //;
< 2>在HTML中嵌入JavaScript代码时,需要避免无效的HTML:
< script type =text / javascript><! -
alert('< / p> ')
// - >< / script>
...触发器:未打开的元素P的结束标签
< script type =text / javascript><! -
alert < \ / p>')
// - >< / script>
...不。
I asked another question poorly so i'll ask something else.
According to http://www.c-point.com/javascript_tutorial/special_characters.htm there are a few escape characters such as \n and \b. However / is not one of them. What happens in this case? (\/
) is the \
ignored?
I have a string in javascript 'http:\/\/www.site.com\/user'
. Not that this is a literal with '
so with "
it would look like \\/
anyways i would like to escape this string thus the question on what happens on non 'special' escape characters.
And another question is if i had name:\t me
(or "name:\\t me"
is there a function to escape it so there is a tab? i am using C# and these strings come from a JSON file
According to Mozilla:
For characters not listed [...] a preceding backslash is ignored, but this usage is deprecated and should be avoided.
https://developer.mozilla.org/en/JavaScript/Guide/Values%2c_Variables%2c_and_Literals#section_19
The \/
sequence is not listed but there're at least two common usages:
<1> It's required to escape literal slashes in regular expressions that use the /foo/
syntax:
var re = /^http:\/\//;
<2> It's required to avoid invalid HTML when you embed JavaScript code inside HTML:
<script type="text/javascript"><!--
alert('</p>')
//--></script>
... triggers: end tag for element "P" which is not open
<script type="text/javascript"><!--
alert('<\/p>')
//--></script>
... doesn't.
这篇关于\对非转义字符做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!