demo.js 586 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. var totalPrice = 0;
  2. function addGoods(price)
  3. {
  4. totalPrice = addPrice(totalPrice, price);
  5. getPrice(totalPrice);
  6. }
  7. function getPrice(price)
  8. {
  9. var f = parseFloat(price);
  10. if (isNaN(f))
  11. {
  12. return false;
  13. }
  14. var f = Math.round(price*100)/100;
  15. var s = f.toString();
  16. var rs = s.indexOf('.');
  17. if (rs < 0)
  18. {
  19. rs = s.length;
  20. s += '.';
  21. }
  22. while (s.length <= rs + 2)
  23. {
  24. s += '0';
  25. }
  26. document.getElementById('MM-Price-span').innerText='$'+s;
  27. }
  28. function addPrice(arg1,arg2)
  29. {
  30. return parseInt(arg1)+parseInt(arg2);
  31. }