<div class="my-box">
<img src="img/01.png"/>
<input type="file" id="file" />
<h4>欢迎您</h4>
<button onclick="logOut()">退出登录</button>
</div>
<script type="text/javascript">
//判断是否登录
if(!localStorage.getItem("name")){
window.location.href="login.html";
}
//退出
function logOut(){
localStorage.setItem("name","");
window.location.reload();
}
//上传图像
var file = document.getElementById('file');
var image = document.querySelector("img");
//判断是否有头像
if(localStorage.getItem('src')){
image.setAttribute("src", localStorage.getItem('src'));
}
//改变头像
file.onchange = function() {
var fileData = th
js上传图片
最新推荐文章于 2024-07-18 20:54:54 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)