jquery - Changing The Arrow Icon In Dropdown To any Icon I want
问题描述
I have a dropdown select on my webpage and i WANT to change the arrow icon into a plus icon. When clicked and the choices show, the "plus" icon turns into a minus icon. How do I code that in jquery. Can someone tell me? I am new in jquery and I want to learn this language. I'll provide a sample code of my work.
<form action="/action_page.php" class = "footer-dropdown">
<fieldset>
<select class = "select-div" name="template">
<option active value="item1">관련사이트</option>
<option value="item2">성신여자대학교</option>
<option value="item3">성신여자대학교 평생교육원</option>
</select>
</fieldset>
</form>
<!-- here is the code snippet of my dropdown menu-->
解决方案
您可以使用切换类 jquery 来完成,非常简单。
$('.sel_par').click(function(){
$(this).toggleClass('open');
});
.sel_par {
position:relative;
width: max-content;
}
.sel_par:after {
content: '+';
display:block;
position:absolute;
right: 10px;
top: 0;
bottom: 0;
margin: auto;
height: max-content;
}
.sel_par.open:after {
content: '-';
display:block;
position:absolute;
right: 10px;
top: 0;
bottom: 0;
margin: auto;
height: max-content;
}
.select-div {
-webkit-appearance: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form action="/action_page.php" class = "footer-dropdown">
<fieldset>
<div class="sel_par">
<select class = "select-div" name="template">
<option active value="item1">관련사이트</option>
<option value="item2">성신여자대학교</option>
<option value="item3">성신여자대학교 평생교육원</option>
</select>
</div>
</fieldset>
</form>
推荐阅读
- css - 用改变数量的子视频元素填充父容器,每个元素都有纵横比
- html - 在 p-panel 内居中对齐 p-chart
- reactjs - 如何以最简洁的方式处理错误和成功响应?
- tweepy - Tweeter API:如何使用 Tweepy.cursor 按关键字搜索(例如 trump)和按关注者数量搜索(例如大于 10000)
- r - highcharter - 如何在地图上的国家/地区显示我的数据值?
- resharper - 有没有办法让 ReSharper 检查正确的文件头
- ruby-on-rails - RSpec:请求规范中的存根控制器方法
- python - 打印数组中的每个单独元素
- image - CachedNetworkImage 和 CachedNetworkImageProvider 有什么区别?应该分别用在哪种情况下?
- r - 通过几乎相同的字符串进行汇总和传播