Blogger Information
Blog 36
fans 1
comment 0
visits 28786
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
12月16日JS基础(变量.流程控制.循环.类型转换)-九期线上班
WJF
Original
629 people have browsed it

javascript变量、函数的定义


  1. <script type="text/javascript">
  2. //变量声明
  3. var a=666;
  4. //输出变量
  5. console.log(a);
  6. //函数定义
  7. function fun(){
  8. console.log('666666666');
  9. }
  10. //函数调用
  11. fun();
  12. </script>


javascript流程控制if else switch


  1. <script type="text/javascript">
  2. //流程控制 IF
  3. function a1(){
  4. var int=1;
  5. if (int>100 || int<0) {
  6. alert('非约定值!!!');
  7. }else if (int>90) {
  8. alert('优秀!');
  9. }else if (int<=90 && int>70) {
  10. alert('及格了');
  11. }else{
  12. alert('没及格 快跑!');
  13. }
  14. }
  15. //流程控制 switch
  16. function a2() {
  17. var int=99;
  18. switch(true){
  19. case(int >100 || int < 0):
  20. alert('分错了!');
  21. break;
  22. case(int>=90):
  23. alert('优秀了!');
  24. break;
  25. case(int>=70):
  26. alert('及格了!');
  27. break;
  28. default:
  29. alert('挨打了!');
  30. }
  31. }
  32. //流程控制 IF优化
  33. function a3(){
  34. var int=1000;
  35. if (int >100 || int < 0) {
  36. alert('报错');
  37. }
  38. if (int>=90 && int <= 100 && int >=0) {
  39. alert('优秀');
  40. }
  41. if (int<=90 && int>=70) {
  42. alert('及格');
  43. }
  44. if (int<70) {
  45. alert('没过')
  46. }
  47. }
  48. a3();
  49. </script>


javascript三种循环

  1. <script type="text/javascript">
  2. //循环 for
  3. function x1(){
  4. for (var i = 1; i <=10; i++) {
  5. console.log(i);
  6. }
  7. }
  8. //循环 while
  9. function x2() {
  10. var i=10;
  11. while(i<=100){
  12. console.log(i);
  13. i+=10;
  14. }
  15. }
  16. //循环 do while
  17. function x3() {
  18. var i=2;
  19. do{
  20. console.log(i);
  21. i+=2;
  22. }while (i<=20);
  23. }
  24. x3();
  25. </script>


数据类型转换:parseInt、isNaN函数的使用

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>数据类型转换:parseInt、isNaN函数的使用</title>
  6. </head>
  7. <body>
  8. <h1>数据类型转换:parseInt、isNaN函数的使用</h1>
  9. <input type="text" name="" id="age" placeholder="输入您的年龄">
  10. <button onclick="ageJc();">提交</button>
  11. <script type="text/javascript">
  12. function ageJc() {
  13. var age=document.getElementById('age').value;
  14. age = parseInt(age);
  15. //isNaN判断值是否为NaN
  16. if (isNaN(age)) {
  17. return alert('年龄值不合法!');
  18. }
  19. if (age>120 || age<0) {
  20. return alert('年龄超过可提交范围,请核实');
  21. }
  22. return alert('您的年龄为【'+age+'】已提交成功!')
  23. }
  24. </script>
  25. </body>
  26. </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