localStorage使用
16lz
2021-11-24
1.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="div" style="height: 200px;width: 200px" >
<button id="button">点击</button>
<button id="button2">点击</button>
</div>
<script>
var div= document.getElementById("div");
var button= document.getElementById("button");
var button2= document.getElementById("button2");
var bgcolor = window.localStorage.getItem('bgcolor');
console.log(bgcolor)
button.onclick=function () {
bgcolor =prompt("请输入颜色");
window.localStorage.setItem('bgcolor',bgcolor);
div.style.background = bgcolor;
}
button2.onclick=function () {
parent.location="2.html"
}
</script>
</body>
</html>
2.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>2</title>
</head>
<body id="body">
<script>
onload=function () {
bgcolor = window.localStorage.getItem('bgcolor');
document.getElementById("body").style.background=bgcolor;
}
</script>
</body>
</html>
更多相关文章
- 带有二级分类的导航
- Element Plus组件-按钮、图标、ColorPicker 颜色选择器、日历、R
- phpstorm 配置环境本地服务器教程
- html5实现点击弹出图片功能
- Vue一个通用的组件传递点击事件的两种种简单方法
- 三分钟!意派Epub360制作高端H5邀请函
- 字体图标引用、无序列表颜色设置、盒模型
- Visual Studio Code如何切换为简体中文
- php之session实战