5.模板字符串.html 773 B

1234567891011121314151617181920212223242526272829303132
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. /**
  11. * 模板字符串(template string)
  12. * 使用反引号(`)
  13. */
  14. /**
  15. * 1.允许使用换行符;
  16. * 2.输出模板:`...${xxx}...`;
  17. */
  18. let str = `
  19. <ul>
  20. <li>1</li>
  21. <li>2</li>
  22. <li>3</li>
  23. </ul>
  24. `
  25. document.write(str);
  26. let name = '图图';
  27. // let result = '我的名字是' + name;
  28. let result = `我的名字是${name}`;
  29. console.log(result);
  30. </script>
  31. </body>
  32. </html>