声明(创建)字符串

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h2>JavaScript 字符串</h2>
  6.  
  7. <p>您可以在字符串内使用引号,只要这些引号与包围字符串的引号不匹配:</p>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. var answer1 = "It's alright"; // 双引号内的单引号
  13. var answer2 = "He is called 'Bill'"; // 双引号内的单引号
  14. var answer3 = 'He is called "Bill"'; // 单引号内的双引号
  15.  
  16. document.getElementById("demo").innerHTML =
  17. answer1 + "<br>" +
  18. answer2 + "<br>" +
  19. answer3;
  20. </script>
  21.  
  22. </body>
  23. </html>