Blogger Information
Blog 37
fans 1
comment 0
visits 27038
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1216_JS初识 第33课
叮叮当当
Original
730 people have browsed it

1、javascript变量、函数的定义

  1. <script type="text/javascript">
  2. // 变量声明
  3. var num2 = 2;
  4. // 函数定义
  5. function myalert1( num2 ){
  6. if( typeof(num2) == 'undefined' ) {
  7. alert( 'num2未定义' );
  8. }
  9. else{
  10. alert( 'num2 = '+num2 );
  11. }
  12. }
  13. myalert1(num2);
  14. </script>

2、javascript流程控制if else switch

  1. <script type="text/javascript">
  2. var myscore = 90;
  3. function func( ) {
  4. if( myscore >= 60 ){
  5. alert('合格');
  6. } else {
  7. alert('不及格');
  8. }
  9. }
  10. //func();
  11. var myscore = 69;
  12. function func2( ) {
  13. switch (true){
  14. case myscore >= 60:
  15. alert('合格');
  16. break;
  17. default:
  18. alert('不及格');
  19. }
  20. }
  21. // func2();
  22. var myscore = 59;
  23. function func3( ) {
  24. if( myscore >= 60 ){
  25. return alert('合格');
  26. }
  27. alert('不及格');
  28. }
  29. func3();
  30. </script>

3、javascript三种循环

  1. <script type="text/javascript">
  2. // for循环
  3. function loop1(){
  4. for( var i=0; i<10; i++ ){
  5. console.log( 'i=' + i );
  6. }
  7. }
  8. // loop1();
  9. // while循环
  10. function loop2() {
  11. var flag = 10;
  12. while( flag > 0 ){
  13. flag--;
  14. if( flag == 6 ) continue; //跳过此次循环
  15. if( flag == 2 ) break; //跳出循环
  16. console.log( 'flag=' + flag);
  17. }
  18. }
  19. loop2();
  20. // do...while循环
  21. function loop3() {
  22. var flag = 10;
  23. do{
  24. flag--;
  25. console.log( 'flag=' + flag);
  26. }while( flag > 0 );
  27. }
  28. // loop3();
  29. </script>

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

  1. <body>
  2. <input type="text" id="username" value="" placeholder="请输入你的年龄">
  3. <button onclick="save()">提交</button>
  4. <script type="text/javascript">
  5. function save() {
  6. var age = document.getElementById('username').value;
  7. age = parseInt( age );
  8. if( isNaN( age ) ){
  9. return alert( '年龄转换失败' );
  10. }
  11. alert( '你的年龄为' + age + '岁' );
  12. }
  13. </script>
  14. </body>


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