onloda事件代码
2025年4月30日小于 1 分钟
示例代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>onload 事件</title>
<style type="text/css">
*
{
margin:0px;
padding:0px;
}
#dvs
{
width:300px;
height:200px;
background:blue;
}
#into .cur
{
width:600px;
transition:all 1s 0.2s ;
cursor:pointer;
background:#c81623;
}
</style>
</head>
<body>
<script type="text/javascript">
//注意当上确定需要最后执行的时候可以添加onload事件,可以解决程序执行顺序的问题
window.onload=function()
{
var dvs=document.getElementById('dvs');
dvs.onclick=function()
{
//设置属性名 属性值
this.setAttribute('class','cur');
}
}
</script>
<!-- 注意行内样式的权重值小于内嵌样式时,样式同样不生效,解决方法可以在外面加一层div,加id来增加权重 -->
<div id='into' >
<div id='dvs' ></div>
</div>
</body>
</html>
onbeforeunload 退出浏览器前的提示
作用: 防止误操作
return e.returnValue