Blogger Information
Blog 34
fans 2
comment 0
visits 23162
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
12月18号作业 js创建对象,定时器小案例
遗忘了寂寞
Original
612 people have browsed it

创建对象

  1. <script type="text/javascript">
  2. //创建对象 方法1:
  3. var obj=new Object();
  4. obj.name="张三";
  5. obj.age="18";
  6. obj.shuohua=function(){
  7. console.log('我会说话');
  8. }
  9. //创建对象 方法2:
  10. var obj2={
  11. name:"李四",
  12. age:"20",
  13. shuohua:function(){
  14. console.log('我说话');
  15. }
  16. }
  17. console.log(obj2);
  18. </script>

传参

  1. <script type="text/javascript">
  2. var obj={
  3. name:"李四",
  4. age:"20",
  5. shuohua:function(str){
  6. console.log('我说话了:'+ str);
  7. }
  8. }
  9. obj.shuohua('你好,js对象')
  10. </script>


定时器小案例

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. </head>
  7. <body>
  8. <button id="btn" onclick="send()" type="button">发送验证码</button>
  9. <script type="text/javascript">
  10. function send(){
  11. var flag=10;
  12. var txt=document.getElementById('btn').textContent;
  13. var tem = setInterval(function(){
  14. document.getElementById('btn').textContent = flag + '秒后重试';
  15. document.getElementById("btn").disabled=true;
  16. flag--;
  17. if(flag==0){
  18. clearInterval(tem);
  19. document.getElementById("btn").disabled=false;
  20. document.getElementById('btn').textContent =txt
  21. }
  22. },1000)
  23. }
  24. </script>
  25. </body>
  26. </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