Blogger Information
Blog 23
fans 0
comment 3
visits 15401
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
12月16号javascript基础——php第九期
木易
Original
622 people have browsed it

1、javascript变量、函数的定义

  1. <script type="text/javascript">
  2. // 定义一个函数
  3. function afun(){
  4. document.write('这是一个函数');
  5. }
  6. afun();
  7. // 定义变量
  8. var a,b,sum;
  9. a= 1;
  10. b =2;
  11. sum =a +b;
  12. console.log(sum);
  13. </script>

2、javascript流程控制if else switch

  1. <script type="text/javascript">
  2. var grade = 89;
  3. if(grade>90){
  4. console.log('成绩优秀继续保持');
  5. }else{
  6. console.log('继续努力');
  7. }
  8. if(grade>90){
  9. console.log('成绩游戏继续保持');
  10. }else if(60<=grade<=90){
  11. console.log('成绩不错继续努力');
  12. }else{
  13. console.log('成绩不合格,加油');
  14. }
  15. var x = 1;
  16. switch(x){
  17. case 0:
  18. console.log('off');
  19. break;
  20. case 1:
  21. console.log('ON');
  22. break;
  23. default:
  24. console.log('no value found');
  25. }
  26. switch (new Date().getDay()){
  27. case 5:
  28. console.log('周末快到了');
  29. break;
  30. case 0:
  31. case 6:
  32. console.log('今天是周末');
  33. break;
  34. default:
  35. console.log('期待周末');
  36. }
  37. </script>

3、javascript三种循环

  1. <script type="text/javascript">
  2. var i= 1;
  3. // while循环
  4. while(i<10){
  5. i++;
  6. }
  7. console.log(i);
  8. // do while循环
  9. do{
  10. i++;
  11. }while(i<11)
  12. console.log(i);
  13. // for循环
  14. for(var i=1;i<20;i++){
  15. }
  16. console.log(i);
  17. </script>

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

  1. <script type="text/javascript">
  2. // parseInt函数练习
  3. var num1 =parseInt('12345red');
  4. document.write(num1+'<br>');
  5. var num1 = parseInt('0xa');
  6. document.write(num1+"<br>");
  7. var num1 = parseInt("56.9");
  8. document.write(num1+'<br>');
  9. var num1 = parseInt('r23');
  10. document.write(num1+'<br>');
  11. // isNaN函数练习
  12. document.write(isNaN(123)+"<br />");
  13. document.write(isNaN(-1.23)+"<br />");
  14. document.write(isNaN(5-2)+"<br />");
  15. document.write(isNaN(0)+"<br />");
  16. document.write(isNaN('HELLO')+"<br />");
  17. document.write(isNaN('2005/12/12')+ "<br />");
  18. </script>

手抄作业


个人感悟:

switch:使用时需要注意条件是恒等于,刚开始在第一个demo中加入了单引号导致无法进入第一个case,反复检查才知道必须恒等于才行。

Correcting teacher:西门大官人西门大官人

Correction status:qualified

Teacher's comments:案例中do while前把i初始化一下:i=0;否则i会从10开始循环
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