作为代数的 JavaScript 变量

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JavaScript 变量</h1>
  6.  
  7. <p id="demo"></p>
  8.  
  9. <script>
  10. var price1 = 7;
  11. var price2 = 8;
  12. var price3 = 12;
  13. var total = price1 + price2 + price3;
  14. document.getElementById("demo").innerHTML = "总计:" + total;
  15. </script>
  16.  
  17. </body>
  18. </html>