div窗口:包含了要输入账号密码的input标签 和 验证是否正确的onclick
要插入的地方:是一个 < li>< a onclick="事件"> Y < /a>< /li>
目标是:点击Y 会出来div里的内容。
请问要在js文件里怎么写,本人刚刚接触请求回答,谢谢~
div窗口:包含了要输入账号密码的input标签 和 验证是否正确的onclick
要插入的地方:是一个 < li>< a onclick="事件"> Y < /a>< /li>
目标是:点击Y 会出来div里的内容。
请问要在js文件里怎么写,本人刚刚接触请求回答,谢谢~
如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
* {
padding: 0;
margin: 0;
}
html,
body {
width: 100%;
height: 100%;
}
.shadow {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
background: rgba(0,0,0,.3);
transition: all .3s;
z-index: -1;
}
.shadow.show {
z-index: 1;
opacity: 1;
}
.shadow.show .model {
transform: translate(-50%, -50%);
}
.model {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -60%);
width: 300px;
background: #fff;
border-radius: 6px;
transition: all .3s;
}
.model .tit {
display: flex;
line-height: 30px;
padding: 10px;
border-bottom: 1px solid #ccc;
}
.model .tit .close {
margin-left: auto;
cursor: pointer;
}
.model .content {
padding: 10px;
}
</style>
</head>
<body>
<a href="void:;" id="btn">按钮</a>
<div class="shadow" id="shadow">
<div class="model">
<div class="tit">
我是弹窗标题
<div class="close" id="model-close">关闭</div>
</div>
<div class="content">
我是弹窗内容
</div>
</div>
</div>
<script>
let btn = document.getElementById('btn');
let shadow = document.getElementById('shadow');
btn.addEventListener('click', function(e) {
shadow.className = 'shadow show'
return false
}, false)
shadow.addEventListener('click', function(e) {
let target = e.target;
let _class = target.className;
if(_class.includes('shadow') || _class.includes('close')) {
shadow.className = 'shadow'
}
return false
}, false)
</script>
</body>
</html>