Date的一些主要方法:
var date=new Date();
//获取当前时间
console.log(date)
//获取当前天数
var day=date.getDate();
//设置具体天数
date.setDate(5) ;
console.log(day)
//获取当前week\n
var 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); //获取url
location.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)