字符串和数字相加的常见错误 1

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JavaScript 数字</h1>
  6.  
  7. <p>一个常见的错误是期望这个结果为 30:</p>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. var x = 10;
  13. var y = 20;
  14. document.getElementById("demo").innerHTML = "结果是:" + x + y;
  15. </script>
  16.  
  17. </body>
  18. </html>