<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>中国的流浪猫</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.box {
overflow: hidden;
width: 300px;
height: 80px;
margin: 100px auto;
background-color: skyblue;
text-align: center;
}
.son {
visibility: hidden;
position: relative;
width: 200px;
height: 30px;
margin: 10px auto 0;
background-color: #fff;
border-radius: 5px;
box-shadow: 2px 2px 2px rgba(0, 0, 0, .4);
text-align: left;
line-height: 30px;
font-size: 20px;
}
.son::after {
content: '';
display: inline-block;
position: absolute;
left: 20px;
bottom: -20px;
border: 10px solid transparent;
border-top-color: #fff;
}
.inp {
width: 200px;
height: 20px;
margin-top: 10px;
border: none;
outline: none;
}
</style>
</head>
<body>
<div class="box">
<div class="son"></div>
<input type="text" class="inp">
</div>
</body>
</html>
<script>
var inp = document.querySelector('.inp')
var son = document.querySelector('.son')
inp.addEventListener('keyup', function () {
if (this.value === '') {
son.style.visibility = 'hidden'
} else {
son.style.visibility = 'visible'
son.innerHTML = this.value
}
})
inp.addEventListener('blur', function () {
son.style.visibility = 'hidden'
})
inp.addEventListener('focus', function () {
if (this.value !== '') {
son.style.visibility = 'visible'
}
})
</script>
js习题(模拟京东快递单号查询)
最新推荐文章于 2022-03-22 11:44:00 发布