<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>js下拉栏</title>
<style>
*{
margin: 0;
padding: 0;
}
li{
list-style: none;
text-align: center;
}
.box>ul{
width: 120px;
background-color: gray;
}
.box>li {
width: 120px;
display: inline-block;
background-color: aqua;
position: relative;
}
.box>li>ul{
width: 120px;
position: absolute;
display: none;
background-color: pink;
}
.box>li>ul>li:hover{
background-color: deeppink;
}
</style>
</head>
<body>
<ul class="box">
<li>asdf
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</li>
<li>asdf
<ul>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>
</li>
<li>asdf
<ul>
<li>7</li>
<li>8</li>
<li>9</li>
</ul>
</li>
</ul>
</body>
</html>
<script>
let $ = element => document.getElementsByClassName(element.substring(1, element.length));
var lis = $(".box")[0].children;
for (let i = 0; i < lis.length; i++) {
lis[i].onmouseover = function () {
this.getElementsByTagName('ul')[0].style.display = 'block';
}
lis[i].onmouseout = function () {
this.getElementsByTagName('ul')[0].style.display = 'none';
}
}
</script>
网站首页 > 基础教程 正文
猜你喜欢
- 2024-07-19 js中string方法(js string函数)
- 2024-07-19 前端干货:JS你必须要知道的知识 大不了重头来
- 2024-07-19 JS 前20个常用字符串方法及使用方式
- 2024-07-19 JavaScript String 对象(javascript的string对象属性及方法)
- 2024-07-19 互联网前端开发技术JavaScript字符串类型详解
- 2024-07-19 快速了解JavaScript的BOM模型(javascript中bom)
- 2024-07-19 JavaScript字符串处理方法(javascript字符串操作函数)
- 2024-07-19 多行内容超出...显示的JS解决方案
- 2024-07-19 通过JavaScript学习不变性(immutability)
- 2024-07-19 JavaScript优雅写法及骚操作(javascript书写)
- 最近发表
- 标签列表
-
- gitpush (61)
- pythonif (68)
- location.href (57)
- tail-f (57)
- pythonifelse (59)
- deletesql (62)
- c++模板 (62)
- css3动画 (57)
- c#event (59)
- linuxgzip (68)
- 字符串连接 (73)
- nginx配置文件详解 (61)
- html标签 (69)
- c++初始化列表 (64)
- exec命令 (59)
- canvasfilltext (58)
- mysqlinnodbmyisam区别 (63)
- arraylistadd (66)
- node教程 (59)
- console.table (62)
- c++time_t (58)
- phpcookie (58)
- mysqldatesub函数 (63)
- window10java环境变量设置 (66)
- c++虚函数和纯虚函数的区别 (66)