定时器和BOM对象和Date类

来源:互联网 发布:淘宝店铺模板代码 编辑:程序博客网 时间:2024/05/16 14:35

Date的一些主要方法:

var date=new Date();//获取当前时间console.log(date)//获取当前天数var day=date.getDate();//设置具体天数 date.setDate(5) ;console.log(day)//获取当前week\nvar week =date.getDay();//获取设置年份date.getFullYear() ;date.setFullYear(2018);//获取月份date.getMonth();console.log(week)//转成世界时间格式var world=date.toUTCString(); //返回毫秒数var d=Date.parse('2017-6-7');var  d=new Date('2017-6-7').getTime();//返回标准数var d=new Date(1483459200000);
BOM一些主要对象的使用:


//判定浏览器类型 var str=navigator.userAgent;    console.log(str);    if(str.indexOf('Android')!=-1){      console.log('你是安卓系统的手机')    }else if(str.indexOf('iPhone')!=-1){      console.log('你是ios系统的手机')    }     //网页后退     history.back();   history.go(-1) ;    //网页前进    history.forward();     history.go(2) ;     //网页刷新       history.go(0);  location.reload();    location.hash = '#1';   //设置#后的字符串,并跳转console.log(location.hash);   //获取#后的字符串console.log(location.port);  //获取当前端口号console.log(location.hostname);   //获取主机名(域名)'detail.tmall.com'console.log(location.pathname);   //获取当前路径(服务器地址后部分)          console.log(location.search);   //获取?后面的字符串console.log(location.href);  //获取urllocation.href = 'http://www.baidu.com';   //设置跳转的URL,并跳转location对象的方法location.assign('http://www.baidu.com');    //跳转到指定的URL, 与href等效location.reload();      //最有效的重新加载,有缓存加载(不会清掉缓存相当于直接按F5)location.reload(true);    //强制加载,从服务器源头重新加载(相当于清除缓存再按F5)location.replace('http://www.baidu.com');  //用新的URL替代,可以避免产生历史记录
定时器与延时器的使用:

 //1s一次重复执行var timer=setInterval(function(){console.log('sss')},1000)//清除定时执行clearInterval(timer);//延时执行一次setTimeout(function(){console.log('sss')},2000) 


原创粉丝点击