JS 特殊字符
来源:互联网 发布:德州扑克机器人软件 编辑:程序博客网 时间:2024/06/05 00:40
In JavaScript you can add special characters to a text string by using the backslash sign.
使用backslash标记你可以在JS中添加特殊文字。
Insert Special Characters
插入特殊文字
The backslash (/) is used to insert apostrophes, new lines, quotes, and other special characters into a text string.
(/)被用来插入省略符号,新的行,引用和其他插入在字符串中的特殊文字。
Look at the following JavaScript code:
请看下面的JS代码:
var txt="We are the so-called "Vikings" from the north."
document.write(txt)
In JavaScript, a string is started and stopped with either single or double quotes. This means that the string above will be chopped to: We are the so-called
在JS中,一字符串可以用单引号或是双引号来开始和结束。这就意味着上面的字符串将被切成:We are the so-called
To solve this problem, you must place a backslash (/) before each double quote in "Viking". This turns each double quote into a string literal:
要解决这个问题,你必须在"Viking"的每个双引号前放置一个(/)。这样就能在字符串中正确返回每个双引号了:
var txt="We are the so-called /"Vikings/" from the north."
document.write(txt)
JavasScript will now output the proper text string: We are the so-called "Vikings" from the north.
现在JS就能输出合适的文字了: We are the so-called "Vikings" from the north.
Here is another example:
这是另外一个例子:
document.write ("You /& me are singing!")
The example above will produce the following output:
上面的例子会输出下面的内容:
You & me are singing!
The table below lists other special characters that can be added to a text string with the backslash sign:
下面的表格罗列了其他一些特殊文字:
代码
输出结果
- JS 特殊字符
- js过滤特殊字符
- js过渡特殊字符
- js中特殊字符
- js过滤特殊字符
- js特殊字符校验
- JS特殊字符 %% && / ? #
- JS特殊字符
- JS处理特殊字符
- js特殊字符验证
- js过滤特殊字符
- JS验证特殊字符
- js特殊字符替换
- js过滤特殊字符
- JS判断特殊字符
- JS特殊字符判断
- js特殊字符验证
- JS去除特殊字符
- 用户控件初学(vs2003)
- 汉诺塔的两种非递归解法
- NOD32 2.70.31 - Best Anti-Virus Out There! (+fix included)
- c++中const用法
- c语言指针详解
- JS 特殊字符
- 怎样规划你毕业以后的人生
- prototype.js常用函数及其用法
- 第一次写文章,没有什么内容,仅仅试试如何发文章
- java数据库操作
- 两道简单的面试题 java
- DirectX 开发环境配置
- 游戏开发技巧二
- 学习完了C++,然后该学什么?