<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>把事件封装成函数给某个元素进行点击</title>
<style type="text/css" >
#leo{width: 500px;height: 500px;border: 2px orange solid;}
</style>
<script type="text/javascript" >
window.onload=function(){
var long=document.getElementById("leo");
function a(){
long.style.backgroundColor="red";
};
long.onclick=a;
};
</script>
</head>
<body>
<div id='leo'></div>
</body>
</html>
把事件封装成函数给某个元素进行点击
最新推荐文章于 2023-04-15 14:26:26 发布