老师,请检测,能优化吗?
来源:5-6 编程练习
慕神4155339
2020-05-06 16:38:30
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<title>5-6 编程练习</title>
<style type="text/css">
#box{position: relative; width: 100px; height: 100px;
background-color: red; margin: 10px auto;}
#close{position: absolute; right: 0px; top: -4px; color: yellow;}
#btn{display: block; width: 100px; margin: 0 auto;}
</style>
</head>
<body>
<div id="box">
<span id="close">X</span>
</div>
<button id="btn">关闭</button>
<script type="text/javascript">
// 在此处补充代码
var obj={
box: document.getElementById("box"),
close: document.getElementById("close"),
btn: document.getElementById("btn")
};
var btn=obj.btn.onclick=function (){
obj.box.style.display="none";
}
obj.close.onclick=function (){
btn();
}
</script>
</body>
</html>1回答
同学你好,这样写就可以,无需优化,很棒,祝学习愉快!
相似问题