Blogger Information
Blog 34
fans 0
comment 0
visits 21639
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
12月18日_ javascript对象,定时器 - 九期线上班
只猫
Original
654 people have browsed it

javascript类与对象

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>javascript对象</title>
  6. </head>
  7. <body>
  8. <script type="text/javascript">
  9. //js对象
  10. //创建方法1
  11. //注意格式
  12. var obj = new Object();
  13. obj.name = "aaa";
  14. obj.age = "18";
  15. console.log(obj);
  16. //创建方法2
  17. var obj1 = {name:"bbb",age:"28"};
  18. console.log(obj1);
  19. //javascript中类的概念较弱,直接定义对象
  20. var obj2 = {
  21. //类属性
  22. name:"aaa",
  23. age:"18",
  24. //类方法
  25. speak:function(){
  26. console.log('speak');
  27. },
  28. };
  29. console.log(obj2);
  30. //类方法调用 在类中调用类方法也需要添加对象名,或者用this
  31. obj2.speak();
  32. </script>
  33. </body>
  34. </html>

定时器

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>js定时器</title>
  6. </head>
  7. <body>
  8. <button id="btn" onclick="send()">发送验证码</button>
  9. <script type="text/javascript">
  10. //js定时器
  11. //setTimeout() 第一个参数是匿名函数 第二个参数是毫秒
  12. setTimeout(function(){
  13. console.log('页面加载完成');
  14. },3000);
  15. //匿名函数执行一次就找不到了 所以这个定时器只执行一次
  16. //js延时器
  17. //setInterval() 第一个参数是匿名函数 第二个参数是毫秒
  18. var stime = setInterval(function(){
  19. console.log('一直执行');
  20. },1000);
  21. //停止
  22. clearInterval(stime);
  23. var aa = setInterval(function(){
  24. if(now < 13){
  25. return;
  26. }
  27. //...
  28. if(now > 14){
  29. clearInterval(aa);
  30. }
  31. },1000);
  32. //发送验证码倒计时
  33. function send(){
  34. var flag = 60;
  35. var txt = document.getElementById('btn').textContent;
  36. var timer = setInterval(function(){
  37. document.getElementById('btn').textContent = flag+'秒后重试';
  38. flag--;
  39. if(flag<0){
  40. clearInterval(timer);
  41. document.getElementById('btn').textContent = txt;
  42. }
  43. },1000);
  44. }
  45. </script>
  46. </body>
  47. </html>

总结:比较实用,以前总是看不懂。经过这段时间对基础的学习以及老师对原理的讲解。感觉代码能清晰了,能看懂。

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!