Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Es6格式错误?_Javascript_Html_Jsp_Ecmascript 6 - Fatal编程技术网

Javascript Es6格式错误?

Javascript Es6格式错误?,javascript,html,jsp,ecmascript-6,Javascript,Html,Jsp,Ecmascript 6,这个字符串变量在js中定义 bodycontent = 'Hello ' + studentName + '%0D%0AThe course ' + courseName + ' is using the TEAMMATES System to collect feedback.%0D%' + '0ATo \'join\' the course, please go to this Web address: '

这个字符串变量在js中定义

bodycontent = 'Hello ' + studentName + '%0D%0AThe course ' + courseName
                + ' is using the TEAMMATES System to collect feedback.%0D%'
                + '0ATo \'join\' the course, please go to this Web address: '
                + encodeURIComponent(uri) + '%0D%0A*If prompted to log in, '
                + 'use your Googleaccount to log in. If you do not '
                + 'have a Google account, please create one from the '
                + encodeURIComponent('https://accounts.google.com/NewAccount')
                + '%0D%0A*The above link is unique to you. Please do not '
                + 'share it with your classmates.%0D%0ANote that If you '
                + 'wish to access TEAMMATES without using your Googleaccount, '
                + 'you do not need to \'join\' the course as instructed '
                + 'above. You will still be able to submit/view feedback '
                + 'by following the instructions sent to you by TEAMMATES at the '
                + 'appropriate times. However, we recommend joining the courseusing '
                + 'your Google account, because it gives you more convenient '
                + 'access to all your feedback stored in TEAMMATES.%0D%0A%0D%0A'
                + 'If you encounter any problems when using the system, you can '
                + 'email TEAMMATES support team at teammates@comp.nus.edu.sg.%0D%0A%0D%0A'
                + 'Regards,%0D%0ATEAMMATES Team.';
对于一行中超过125个字符的字符,我使用+将其打断到下一行。现在的问题是当我将其转换为ES6时

        bodycontent = `Hello ${studentName}%0D%0AThe following feedback session is ${status}%0D%0A`
                   + `Course: [${Id}]${courseName}%0D%0AFeedback Session Name: ${Id}%0D%0A`
                   + `The link of the feedback for the above session, please go to this Web `
                   + `address: ${encodeURIComponent(uri)}%0D%0A*The above link is unique to you.`
                   + `Please do not share it with others.%0D%0A%0D%0AIf you encounter any problems`
                   + `when using the system, you can email TEAMMATES support team at teammates@comp.nus.edu.sg.%0D%0A%0D%0ARegards,%0D%0ATEAMMATES Team.`;
这显示了在不包含变量的每一行中,erro“字符串必须使用单引号”

我也能像这样打破界限

bodycontent = `Hello ${studentName}%0D%0AThe following feedback session is ${status}%0D%0A
                    Course: [${Id}]${courseName}%0D%0AFeedback Session Name: ${Id}%0D%0A
                    The link of the feedback for the above session, please go to this Web 
                   address: ${encodeURIComponent(uri)}%0D%0A*The above link is unique to you.`
                   ......

但问题是我在字符串中添加了“\n”换行符,我不想告诉我不在字符串中添加“\n”换行符的有效方法。

使用带有
通用标记的很棒的前缀模板文本。如果不使用npm,也可以复制实现


该标记将所有换行和缩进更改为一个空格。如果还想去掉最后一个空格,请使用。

模板文字中包含的任何空格也将包括在内,这就是您接收换行符的原因这是模板文本的预期行为。模板文本的这一功能允许使用它在多行上创建字符串,而不需要解决方法,例如:

$('div.post').html("<h3>Some title here</h3> " +
  "<p>Lorem ipsum doloramet, onsectetur adipiscing elit " +
  "sed do eiusmod tempor incididunt ut labore...");
$('div.post').html(“此处有一些标题”+
“Lorem ipsum doloramet,直面精英”+
“这是临时劳动合同……”;
变成:

$('div.post').html(`
  <h3>Some title here</h3>
  <p>Lorem ipsum doloramet, onsectetur adipiscing elit
  sed do eiusmod tempor incididunt ut labore...
`);
$('div.post').html(`
这里有一些标题
Lorem ipsum doloramet,直面精英
这是临时性的劳动合同。。。
`);

由于字符串的长度,您似乎只想在多行上运行,因此此问题与您的主观文本编辑偏好有关

建议的解决方案:

您是否尝试过在IDE中使用文本换行