jquery - 更改隐藏/显示链接的背景图像并切换 ul
问题描述
当我单击作为背景图像的“+”符号时,我正在尝试扩展“ul”。同时,我希望那个“+”号的背景图像更改为https://image.ibb.co/d7gQUo/genmoo_Hide.jpg。
我希望你们能帮助我。我是 Jquery 的新手,解决这个问题会教会我很多。我从来没有尝试过在单击时发出 2 个命令,即切换所单击链接的背景图像并隐藏/显示其下的列表。
@charset "utf-8";
* {
padding:0;
margin:0;
}
body {
font-family:Arial, Helvetica, sans-serif;
}
.panel {
width:200px;
padding:20px;
border:1px solid #ccc;
position:relative;
}
h3 {
font-size:1em;
line-height:20px;
}
span.hideshow {
position:absolute;
top:20px;
right:20px;
}
span.hideshow a {
display:block;
height:20px;
width:20px;
text-indent:-9999px;
background-image:url("https://image.ibb.co/bvkkUo/genmoo_Show.jpg");
/* URL for show image = https://image.ibb.co/bvkkUo/genmoo_Hide.jpg */
}
ul {
display:none;
margin-top:15px;
list-style-type:none;
}
li {
line-height:24px;
border-bottom:1px solid #eee;
}
li:last-child {
border-bottom:none;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Hide Show Test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div class="panel">
<h3>Teams</h3>
<span class="hideshow"><a href="#">.</a></span>
<ul>
<li>Arsenal</li>
<li>Chelsea</li>
<li>Liverpool</li>
<li>Man United</li>
</ul>
</div>
</body>
</html>
解决方案
我认为你应该使用切换按钮,请检查这个例子
input[type="checkbox"] {
display:none;
}
input[type="checkbox"] + span {
display:inline-block;
width:19px;
height:19px;
padding-top: 5px; /* align the label with the image*/
vertical-align:middle;
background:url(http://icons.iconseeker.com/png/fullsize/mazes-mini/02-laugh.png) left top no-repeat;
cursor:pointer;
}
input[type="checkbox"]:checked + span {
background:url(http://icons.iconseeker.com/png/fullsize/mazes-mini/01-smile.png) left top no-repeat;
}
<label>Expand
<input type="checkbox" id="c1" name="cc" class="mycheckbox" />
<span></span>
</label>
推荐阅读
- c - 如何在C中清除控制台而不闪烁
- python - 使用 python 从 Cassandra 数据库中检索数据
- database - 我可以为 MongoDB 索引配置特定路径吗?
- html - 如何对齐网格系统html/css?
- docker - 无法到达 docker 容器 - 端口未绑定
- html - 响应式列,防止孩子在折叠时在列之间移动
- javascript - 在 mapbox 中读取 GPX 文件或第三方 URL 以添加行
- python - 为什么这个带有浮点除法的 Django 查询注释这么慢?
- android - java.lang.IllegalStateException: WorkManager 已经初始化。即使工作管理器未初始化
- google-pay - 在 Google 支付网关中没有可用于此商家的可接受的卡