Two Methods of addition operation written in Javascript

Source: Internet
Author: User

Two Methods of addition operation written in Javascript

Code:
  1. <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
  2. <HTML>
  3. <Head>
  4. <Title> demo01.html </title>
  5. <Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
  6. <Meta http-equiv = "Description" content = "this is my page">
  7. <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
  8. <! -- <LINK rel = "stylesheet" type = "text/CSS" href = "./styles.css"> -->
  9. <SCRIPT type = "text/JavaScript" src = "./JS/demo01.js">
  10. </SCRIPT>
  11. <SCRIPT type = "text/JavaScript">
  12. // Method 1
  13. Function sum (sums ){
  14. VaR num1 = Document. getelementbyid ("num1"). value;
  15. VaR num2 = Document. getelementbyid ("num2"). value;
  16. VaR num3 = eval (num1 + num2 );
  17. Document. getelementbyid ("num3"). value = num3;
  18. }
  19. // Method 2
  20. Function sum1 (){
  21. VaR num1 = Document. getelementbyid ("num1"). value;
  22. VaR num2 = Document. getelementbyid ("num2"). value;
  23. If (isnan (num1 )){
  24. Alert ("the format of the first input box is incorrect. Enter a number of non-character types ");
  25. } Else {
  26. If (isnan (num2 )){
  27. Alert ("the format of the second input box is incorrect. Enter a number of non-character types ");
  28. } Else {
  29. VaR num11 = parseint (num1 );
  30. VaR num22 = parseint (num2 );
  31. VaR num3 = num11 + num22;
  32. Document. getelementbyid ("num3"). value = num3;
  33. }
  34. }
  35. }
  36. </SCRIPT>
  37. </Head>
  38. <Body>
  39. <Input type = "text" name = "num1" id = "num1">-<input type = "text" name = "num2" id = "num2">
  40. <Input type = "button" value = "=" onclick = "sum ('-')"> <! -- Method 1 -->
  41. <! -- <Input type = "button" value = "=" onclick = "sum1 ()"> --> <! -- Method 2 -->
  42. <Input type = "text" name = "num3" id = "num3">
  43. </Body>
  44. </Html>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.