如何在JavaScript字符串中包含双引号以在浏览器中显示?
我正在处理我的JavaScript作业,我必须在列表中间包含双引号,如下所示:
if (i == 0) {
error += "<li> this is not the name "....." </li>\n"
}
Run Code Online (Sandbox Code Playgroud)
Ale*_*lex 53
使用单引号.
error += '<li> this is not the name "....." </li>\n';
Run Code Online (Sandbox Code Playgroud)
或者逃避双引号.
error += "<li> this is not the name \".....\" </li>\n";
Run Code Online (Sandbox Code Playgroud)
使用单引号作为字符串分隔符:
if (i == 0) {
error += '<li> this is not the name "....." </li>\n'
}
Run Code Online (Sandbox Code Playgroud)
如果字符串中有单引号,请用双引号分隔。
如果字符串中有双引号,请用单引号分隔。
如果您需要在字符串中同时使用这两种类型,请通过在它前面加上前缀来转义您选择的任何分隔符\。
| 归档时间: |
|
| 查看次数: |
70693 次 |
| 最近记录: |