确认框 window.confirm()用于验证是否接受用户操作
console.log(window.location.search);
console.log(window.location.href)
console.log(window.location.port)
复制代码
页面操作
页面后退
function back(){
方法一
}
页面前进
function forward(){
方法一
window.history.go(1);
方法二
window.history.forward();*/
}
页面刷新
function forward(){
方法一
window.history.go();*/
方法二
window.history.go(0);
方法三
location.reload();
}
复制代码
定时器
let id = setInterval(function(){
console.log('我爱js<br>');
console.log(id);
},1000)
function clearfn(){
clearInterval(id)
}
复制代码
setTimeout
setTimeout(function()
console.1og('我说冷笑话');
},1000)
复制代码
会话存储和获取
function fn1(){
sessionstorage.setItem('name','zhangsan')
简写
sessionstorage. name = ' zhangsan';
}
function fn2(){
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();
}