JavaScript字符串中的双引号如何在JavaScript字符串中包含双引号以在浏览器中显示?我正在处理我的JavaScript作业,我必须在列表中间包含双引号,如下所示:if (i == 0) {
error += "<li> this is not the name "....." </li>\n"}
3 回答

牛魔王的故事
TA贡献1830条经验 获得超3个赞
使用单引号。
error += '<li> this is not the name "....." </li>\n';
或者逃避双引号。
error += "<li> this is not the name \".....\" </li>\n";

蓝山帝景
TA贡献1843条经验 获得超7个赞
使用单引号作为字符串分隔符:
if (i == 0) { error += '<li> this is not the name "....." </li>\n'}
如果字符串中有单引号,请用双引号分隔。
如果字符串中有双引号,请用单引号分隔。
如果您需要在字符串中使用这两种类型,请通过在其前面添加一个代码来转义您选择的分隔符\
。

MMTTMM
TA贡献1869条经验 获得超4个赞
error += "<li> this is not the name “.....” </li>\n"
或者,如果您使用英语的变体,其中单引号是常态,像往常一样在英式英语中,
error += "<li> this is not the name ‘.....’ </li>\n"
使用正确的标点符号,您将不会遇到JavaScript引用约定的问题。计算机语言使用ASCII引号,人类语言则不使用。
只需确保您的文档已正确编码(Windows-1252和UTF-8都可以在此处执行)并正确声明编码。
添加回答
举报
0/150
提交
取消