Blogger Information
Blog 31
fans 0
comment 0
visits 18234
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JS第1课-JavaScript基础-九期线上班
Content っ
Original
605 people have browsed it
  1. 1javascript变量、函数的定义
  2. 2javascript流程控制if else switch
  3. 3javascript三种循环
  4. 4、数据类型转换:parseIntisNaN函数的使用
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. </head>
  7. <body>
  8. <input type="text" id="age" placeholder="请输入您的年龄">
  9. <button onclick="save()">提交</button>
  10. <!--script-->
  11. <script>
  12. /***************变量定义 var **********/
  13. var age = 1;
  14. var name = "jason";
  15. var newFloat = 1.1;
  16. /***************函数**********/
  17. //函数的定义
  18. function func1() {
  19. //控制台输出
  20. console.log("哈哈哈");
  21. }
  22. function func2(name) {
  23. console.log(name);
  24. }
  25. function func3(age) {
  26. return age+1;
  27. }
  28. //调用函数
  29. func1();
  30. func2('jack');
  31. console.log(func3(1));
  32. /***************变量的作用域**********/
  33. function func4(num1) {
  34. var num = 5;
  35. console.log(num);
  36. return num + num1;
  37. }
  38. console.log(func4(age));
  39. //使用全局函数
  40. console.log(age);
  41. //调用局部变量失败
  42. // console.log(num);
  43. /***************流程控制**********/
  44. var sore = 90;
  45. function if1() {
  46. //if
  47. if (sore >80){
  48. console.log("成绩优秀");
  49. }
  50. }
  51. //if else
  52. function if2() {
  53. if (sore >= 60){
  54. console.log("及格");
  55. }else {
  56. console.log("不及格");
  57. }
  58. }
  59. //if elseif
  60. function if3() {
  61. if (sore >= 90){
  62. console.log("优秀");
  63. }else if (sore >= 80){
  64. console.log("良好");
  65. }else if (sore>=60){
  66. console.log("及格");
  67. }else {
  68. console.log("不及格");
  69. }
  70. }
  71. //switch 一般用于单值匹配
  72. switch (sore) {
  73. case 100:
  74. case 90:
  75. console.log("优秀");
  76. break;
  77. case 89:
  78. case 70:
  79. console.log("一般");
  80. break;
  81. case 69:
  82. case 60:
  83. console.log("及格");
  84. break;
  85. default:
  86. console.log("不及格");
  87. }
  88. /***************循环**********/
  89. function for1() {
  90. for (var j = 0;j < 10; j++ ){
  91. console.log(j);
  92. }
  93. }
  94. function for2() {
  95. var i = 0;
  96. while (i < 5){
  97. i++;
  98. console.log(i);
  99. }
  100. }
  101. function for3() {
  102. var i = 5;
  103. do {
  104. i--;
  105. console.log(i);
  106. }while (i > 0)
  107. }
  108. /**********typeof、parseInt、isNaN函数的使用********/
  109. function typeofFunc() {
  110. var intStr = 10;
  111. if (typeof(intStr) == 'undefined' ){
  112. alert("未定义");
  113. }else {
  114. alert(intStr+5);
  115. }
  116. }
  117. function save() {
  118. var age = document.getElementById('age').value;
  119. //转换为int类型
  120. age = parseInt(age);
  121. if (age < 1 || age > 130){
  122. alert("您输入的年龄不合法");
  123. }
  124. if (isNaN(age)){
  125. alert("年龄不能为空,请重新输入");
  126. }
  127. }
  128. </script>
  129. </body>
  130. </html>
Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post