当前位置:网站首页>关于页面初始化
关于页面初始化
2022-08-09 10:10:00 【sun*san】
今天想把导航栏导入一个单独的html页面时,发现导航栏竟然不能初始化
我之前用的是js的页面初始化的方法
// 1.在body里面写初始化方法.
<body οnlοad='init()'>
</body>
<script type="text/javascript">
function init(){
// 初始化内容
}
</script>
// 2.window.οnlοad=function(){}
<script type="text/javascript">
window.οnlοad=function(){
// 初始化内容
}
于是我换成了jq的页面初始化的方法
$(document).ready(function(){
console.log("1111")
let user = localStorage.getItem("user");
user=JSON.parse(user);
console.log(user)
if(user==null){
document.getElementById("avatar").style.display="none"
document.getElementById("collect").style.display="none"
document.getElementById("action").style.display="none"
document.getElementById("msg").style.display="none"
document.getElementById("out_btn").style.display="none"
document.getElementById("login-btn").style.display="block"
}else {
if(user.avatar!=null){
document.getElementById("avatar").style.background = "url(" + user.avatar + ") no-repeat";
document.getElementById("avatar").style.backgroundSize="100% 100%"
}
}
});
就成功初始化了,就说明,当把一个html页面引入另一个html页面时,初始化需要用jq的初始化方法
这里再提供一个jq初始化方法
<script type="text/javascript">
$(function() {// 初始化内容
});
</script>边栏推荐
猜你喜欢
随机推荐
JDBC中的增删改查操作
【八大排序④】归并排序、不基于比较的排序(计数排序、基数排序、桶排序)
MySQL索引、视图、设计三范式,通俗易懂,不可错过!
梦笔记0809
LeetCode179:最大数(C语言)代码简洁!
缓存击穿,缓存穿透,缓存雪崩的解释和对应的一些解决方案
MySQL常用存储引擎,你不可错过的知识点!
m个样本的梯度下降
4. Generics and Utilities
实验室装修及改造工程程序简介
多线程案例——定时器
MySQL约束关系,你必须要知道的知识点!
[Halcon&定位] 解决Roi区域外的模板匹配成功
集合与函数
2021-01-11-雪碧图做表情管理器
Battery modeling, analysis and optimization (Matlab code implementation)
[贴装专题] 基于多目视觉的手眼标定
mysql 修改密码和忘记密码操作
MySQL全文索引
GeoScene Pro 2.1下载地址与安装基本要求


![[Machine Learning] Detailed explanation of web crawler combat](/img/ac/f00f0c81e66ba526ac39ee60fad72b.png)





