使用级联运算符 (+) 将两个字符串相加

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JavaScript 运算符</h1>
  6.  
  7. <p>+ 运算符串联(相加)字符串。</p>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. var txt1 = "Bill";
  13. var txt2 = "Gates";
  14. document.getElementById("demo").innerHTML = txt1 + " " + txt2;
  15. </script>
  16.  
  17. </body>
  18. </html>