Blogger Information
Blog 16
fans 7
comment 1
visits 11492
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
12月16日- JS基础(一)
Eric
Original
589 people have browsed it

1、javascript变量、函数的定义

  1. <script>
  2. var name = 'php中文网';
  3. var site = 'www.php.cn';
  4. function getName() {
  5. console.log(name);
  6. }
  7. function getSite() {
  8. console.log(site);
  9. }
  10. //调用方法
  11. getName();
  12. getSite();
  13. </script>

2、javascript流程控制if else switch

  1. <script>
  2. // if
  3. var stars = 100;
  4. if (stars > 112) {
  5. alert('最强王者');
  6. }
  7. if (stars <= 112 && stars > 87) {
  8. alert('至尊星耀');
  9. }
  10. if (stars <= 87 && stars > 62) {
  11. alert('永恒钻石');
  12. }
  13. if (stars <= 62 && stars > 37) {
  14. alert('尊贵铂金');
  15. }
  16. if (stars <= 37) {
  17. alert('都是小学生...');
  18. }
  19. // if...else...
  20. var a = 200;
  21. var b = 300;
  22. if (a > b){
  23. alert('a 大于 b');
  24. }else {
  25. alert('a 小于 b');
  26. }
  27. // switch...case...
  28. var status = 2;
  29. switch (status) {
  30. case 0:
  31. alert('已取消');
  32. break;
  33. case 1:
  34. alert('已下单');
  35. break;
  36. case 2:
  37. alert('已付款');
  38. break;
  39. case 3:
  40. alert('已发货');
  41. break;
  42. case 4:
  43. alert('已收货');
  44. break;
  45. case 5:
  46. alert('已评论');
  47. break;
  48. }
  49. </script>

3、javascript三种循环

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

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

  1. </script>
  2. var age = '30';
  3. console.log(parseInt(age)); //输出:30
  4. if (isNaN(age)){
  5. console.log('是数字');
  6. }else {
  7. console.log('非数值类型');
  8. }
  9. // 输出:非数值类型
  10. </script>

THE END !

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

Correction status:qualified

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