ECMAScript是一种语法标准 语法、变量和数据类型、运算符、逻辑控制语句、关键字、保留字、对象 编码遵循ECMAScript标准
BOM:Browser Object Model(浏览器对象模型) 提供了独立于内容与浏览器窗口进行交互的对象
确认框 window.confirm()用于验证是否接受用户操作
/*这个是地址的参数信息*/
console.log(window.location.search);
/*这是地址路径*/
console.log(window.location.href)
/*这个是地址的端口*/
console.log(window.location.port)
页面的简单操作
页面后退
function back(){
方法一
/*window.history.back();
方法二
window.history.go(-1);*/
}
页面前进
function forward(){
方法一
window.history.go(1);
方法二
window.history.forward();*/
}
页面刷新
function forward(){
方法一
window.history.go();*/
方法二
window.history.go(0);
方法三
location.reload();
}
定时器
/* 过个一段时间去做一件事 */
/* 定时器 */
/* 定时器会返回一个唯一的id */
let id = setInterval(function(){
console.log('我爱js<br>');
console.log(id);
},1000)
/* 根据定时器返回的唯一的id 来清除定时器 */
function clearfn(){
clearInterval(id)
}
setTimeout和setInterval的区别是setTimeout只执行一次
setTimeout(function()
console.1og('我说冷笑话');
},1000)
会话存储和获取
function fn1(){
/*setItem设置存储*/
sessionstorage.setItem('name','zhangsan')
简写
sessionstorage. name = ' zhangsan';
}
function fn2(){
/*getItem获取*/
let v = sessionstorage.getItem('name');document.write(v);
简写
document. write(sessionstorage. name);}
本地储存与获取
function fn1(){
localstorage. setItem(' car',' bmw')
简写()
localStorage. carf= ' bc'
}
function fn2({
document. write (localstorage . getItem(' car'));
简写
document. write (localstorage. car);
}。
字符串转对象
JsoN.stringify把对象转成字符let s = JsoN.stringify(obj1);
localstorage.s = s;
/*再把字符串转成对象*/
let objs = JSON.parse(localstorage.s)
document.write(objs.name)
跳转
location.replace
用新的路径来替换当前的路径replace代表替换,把会历史记录里面的地址也替换了,所以没有返按钮
window.open会打开一个新的tab页不会关闭之前的tab页
window.open(_self )和 location.href功能一样在原来的tab页上打开
清除储存
function clearOne(){
/* 清除指定的一项 */
sessionStorage.removeItem('a')
}
function clearAll(){
/* 全部清除 */
sessionStorage.clear();
}