jquery+css实现下拉列表代码

2019-03-2115:53:11WEB前端开发Comments1,646 views字数 1734阅读模式

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>fruit</title>
<style type="text/css">文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10190.html

.hide {
display: none;
}
div {
float: left;
width: 100%;
}
.selector-containter {
margin-bottom: 10px;
}
.selector {
width: 200px;
background: #FFF;
border: 1px solid #DDD;
}
.selector-hint {
width: 178px;
border: 1px solid #DDD;
}
.selector-expand {
width: 8px;
border: 1px solid #DDD;
}
.selector-collapse {
width: 8px;
border: 1px solid #DDD;
}
</style>
<script src="jquery-3.2.1.min.js"></script>
<script>
$(document).ready(function() {文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10190.html

//使用on方法,采用事件委派机制,selector-option-container中的内容为后续动态追加
$('.selector').on('click', '.selector-expand', function() {
$(this).parent().children('.selector-option-container').children().remove();
$(this).parent().children('.selector-option-container').append('<div><input type="checkbox"/></div><div>apricot</div>');
$(this).parent().children('.selector-option-container').append('<div><input type="checkbox"/></div><div>banana</div>');文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10190.html

$(this).nextAll('.selector-option-container').removeClass('hide');
});
$('.selector').on('click', '.selector-collapse', function() {
$(this).nextAll('.selector-option-container').addClass('hide');
});文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10190.html

$('.selector-t1').on('click', '.selector-option', function() {
$(this).parent().parent().children('.selector-hint').text($(this).text());文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10190.html

$(this).parent().addClass('hide');
});文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10190.html

$('.selector-t1').on('click', '.selector-checkbox', function() {
$(this).parent().parent().parent().children('.selector-hint').text($(this).parent().next().text());文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10190.html

//采用prop方法,对于值为布尔型的属性赋值
$(this).prop('checked', false);文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10190.html

$(this).parent().parent().addClass('hide');
});
});
</script>
</head>
<body>
<div>
<div>
<div>
<div>select fruit</div>
<div>+</div>
<div>-</div>
<div>
</div>
</div>
</div>
</div>
<div>
<div>
<div>
<div>select fruit</div>
<div>+</div>
<div>-</div>
<div>
</div>
</div>
</div>
</div>
</body>
</html>文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10190.html

 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10190.html

文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10190.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/gcs/10190.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定