博客列表 >前端第十三课:javascript基础2-PHP培训九期线上班

前端第十三课:javascript基础2-PHP培训九期线上班

渡劫小能手
渡劫小能手原创
2019年12月21日 23:36:45443浏览

对象

定义对象

  1. var obj = new Object();
  2. obj.name="bo";
  3. obj.age = "18";
  4. obj.abb = function(){
  5. console.log('我说话');
  6. };
  7. obj.abb();
  1. var obj = {name: "bo", age: "18"};
  2. obj.addr = "shen zhen";
  3. obj.speak = function(str){
  4. console.log('我会说话了【'+str+'】');
  5. }
  6. obj.speak('hello js object');
  1. var obj = {
  2. name:"bo",
  3. age:18,
  4. speek:function(str,str2){
  5. console.log('我说话了: '+str);
  6. console.log('str2='+str2);
  7. },
  8. speek2:function(){
  9. this.speek('speek2 调用了speek','aa');
  10. }
  11. }
  12. obj.speek2();

定时器

setTimeout()

只执行一次延时

  1. setTimeout(function () {
  2. console.log('页面加载');
  3. }, 3000);

setInterval()

一直执行,使用 clearInterval() 结束

  1. var haak = setInterval(function(){
  2. console.log('this is setInterval()');
  3. clearInterval(haak);
  4. },1000);

倒计时

  1. function send(){
  2. var flag=10;
  3. var txt = document.getElementById('btn').textContent;
  4. var timer = setInterval(function(){
  5. document.getElementById('btn').textContent = flag+'秒后重试';
  6. flag--;
  7. if(flag==0){
  8. document.getElementById('btn').textContent = txt;
  9. clearInterval(timer);
  10. }
  11. },1000);
  12. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议