<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="chufang/flex.less"/>
<link rel="stylesheet" type="text/css" href="iconfont.css"/>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
html{font-size: 14px;}
ul{
list-style: none;
}
.select-wrapper{
position: relative;
z-index: 1;
margin:20px;
}
.input-wrapper{
position: relative;
}
.input-container{
width:380px;
height: 40px;
margin-bottom: 10px;
box-sizing: border-box;
}
.item-input-style{
-webkit-appearance: none;
background-color: #fff;
background-image: none;
border-radius: 4px;
border: 1px solid #dcdfe6;
box-sizing: border-box;
color: #606266;
display: inline-block;
font-size: inherit;
height: 40px;
line-height: 40px;
outline: none;
padding: 0 15px;
transition: border-color .2s cubic-bezier(.645,.045,.355,1);
width: 100%;
}
.item-input-style:hover{border-color: #c0c4cc;}
.item-input-style:focus{
border-color: #409eff;
}
.input-wrapper .item-input{
padding-right: 30px;
cursor: pointer;
}
.input-wrapper span{
position: absolute;
top: 0;
right: 5px;
cursor: pointer;
width: 25px;
line-height: 40px;
text-align: center;
color: #c0c4cc;
transition: all .3s;
}
.option-wrapper{
display: none;
position: absolute;
top: 45px;
left: 0;
z-index: 2019;
border: 1px solid #e4e7ed;
border-radius: 4px;
background-color: #fff;
box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
box-sizing: border-box;
margin: 5px 0;
}
.ul-wrapper{
padding: 6px 0;
box-sizing: border-box;
}
.ul-wrapper li:hover{
background-color: #f5f7fa;
}
.ul-wrapper li{
padding: 0 20px;
position: relative;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
color: #606266;
height: 34px;
line-height: 34px;
box-sizing: border-box;
cursor: pointer;
}
.ul-wrapper .item-li-active{
color: #409eff;
font-weight: 700;
}
/*复选框*/
.checkout-container{
width:380px;
min-height: 40px;
margin-bottom: 10px;
color: #606266;
box-sizing: border-box;
cursor: pointer;
}
.item-label{
box-sizing: border-box;
width: 80px;
height: 40px;
line-height: 40px;
padding-right: 12px;
text-align: right;
vertical-align: middle;
color: #606266;
}
.checkbox-container{
width: 150px;
line-height: 40px;
box-sizing: border-box;
}
.checkbox-color{color: #409eff;}
</style>
</head>
<body>
<div class="select-wrapper">
<div class="input-wrapper input-container">
<input class="item-input item-input-style" type="text" readonly="readonly" placeholder="请选择月份"/>
<span class="iconfont icon-iconset0417 aside-icon"></span>
</div>
<div class="option-wrapper">
<ul class="ul-wrapper">
<li>一月</li>
<li>二月</li>
<li>三月</li>
<li>四月</li>
</ul>
</div>
<div class="input-container">
<input class="item-input-style" type="text" placeholder="请输入信息"/>
</div>
<div class="checkout-container flex">
<label class="item-label growShrink">活动性质</label>
<div class="checkbox-wrapper all flex wrap">
<div class="checkbox-container">
<span class="span-icon iconfont icon-gouxuan-weixuanzhong-xianxingfangkuang"></span>
<span class="span-text">美食/餐厅线上活动</span>
</div>
<div class="checkbox-container">
<span class="span-icon iconfont icon-gouxuan-weixuanzhong-xianxingfangkuang"></span>
<span>地推活动</span>
</div>
<div class="checkbox-container">
<span class="span-icon iconfont icon-gouxuan-weixuanzhong-xianxingfangkuang"></span>
<span>线下主题活动</span>
</div>
<div class="checkbox-container">
<span class="span-icon iconfont icon-gouxuan-weixuanzhong-xianxingfangkuang"></span>
<span>单纯品牌曝光</span>
</div>
</div>
</div>
</div>
<script src="jquery-2.1.4.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function(){
var inputWidth=$(".input-wrapper").width()-2;
$(".option-wrapper").width(inputWidth);
var optionwrapper=$(".option-wrapper");
var aside=$(".aside-icon");
$(".input-wrapper").click(function(e){
var _this=$(this);
if(optionwrapper.css('display')=='none'){
optionwrapper.show();
aside.removeClass('icon-iconset0417').addClass('icon-iconset0418');
}else{
optionwrapper.hide();
aside.removeClass('icon-iconset0418').addClass('icon-iconset0417');
}
var inputVal=_this.find('input').val();
if(inputVal!="")
$(".option-wrapper li:contains(" +inputVal + ")").addClass('item-li-active').siblings().removeClass('item-li-active');
e.stopPropagation()
})
$(".option-wrapper").on('click','li',function(){
var _this=$(this);
var liText=_this.html();
$(".item-input").val(liText);
optionwrapper.hide();
aside.removeClass('icon-iconset0418').addClass('icon-iconset0417');
})
$(document).on({
"click": function(e){//除了.input-wrapper 之外点击任何地方都会隐藏optionwrapper
var src = e.target;
if(src.class && src.class ==="input-wrapper"){
return false;
}else{
optionwrapper.hide();
aside.removeClass('icon-iconset0418').addClass('icon-iconset0417');
}
}
});
//复选框
$(".checkbox-container").click(function(){
var _this=$(this);
var spanIcon=_this.find(".span-icon");
if(spanIcon.hasClass('icon-gouxuan-weixuanzhong-xianxingfangkuang')){
_this.addClass('checkbox-color');
spanIcon.removeClass('icon-gouxuan-weixuanzhong-xianxingfangkuang').addClass('icon-gouxuan-xuanzhong-fangkuang');
}else{
_this.removeClass('checkbox-color');
spanIcon.addClass('icon-gouxuan-weixuanzhong-xianxingfangkuang').removeClass('icon-gouxuan-xuanzhong-fangkuang');
}
})
})
</script>
</body>
</html>

效果:

模拟select下拉框、复选框效果的更多相关文章

  1. jquery实现模拟select下拉框效果

    <IGNORE_JS_OP style="WORD-WRAP: break-word"> <!DOCTYPE html PUBLIC "-//W3C// ...

  2. 关于通过jq /js 实现验证单选框 复选框是否都有被选中

    今天项目中遇到一个问题 就是要实现,单选框,复选框 同时都被选中才能进行下一步的问题,开始用js原生来写 怎么写都觉得不合适,通过for循环得出 复选框被选中的,在通过for循环得出单选框被选中的,问 ...

  3. jQuery插件:模拟select下拉菜单

    没搞那么复杂,工作中,基本够用.. <!doctype html> <html> <head> <meta charset="utf-8" ...

  4. 联合县城市,采用ajax,而使用ul模拟select下拉

    接待处代码 js //采用jquery展示鼠标放到省ul下拉显示 $("#province").hover(function(){                          ...

  5. ops-web运维平台-create.jsp-mootools下拉框-复选框

    create.jsp页面的,body部分 <body onload="Page.init('${pageError}','${pageMessage}',${isSubmit},tru ...

  6. 如何在select下拉列表中添加复选框?

    近来在给一个公司做考试系统的项目,遇到的问题不少,但其中的几个让我对表单的使用颇为感兴趣,前端程序员都知道,下拉列表有select标签,复选框有checkbox,但是两者合在一起却少有人去研究,当时接 ...

  7. jquery单选框 复选框表格高亮 选中

    单选框: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/T ...

  8. 纯css3单选框/复选框美化样式代码

    纯CSS 单/复选框 美化请选择iPhone 型号 iPhone 6s iPhone 6s Plus iPhone 7 iPhone 7 Plus   选择兴趣爱好 女 绘画 摄影 骑行   原理在这 ...

  9. 单选框 复选框 隐藏之后,绑定的change事件在ie中失效的问题

    有时候需要对单选框和复选框进行美化,就需要在<input type="radio">和<input type="checkbox">元素 ...

随机推荐

  1. Halcon10.0 + VS2010

    新建一个C++空项目 添加c1.pp 复制example1.cpp的代码 配置include\lib\bin\Linker之后

  2. Windows10 + VS2015 环境下对gdal2.0.1进行64bit编译小结

    这是官方给出的编译指导,但是在实践过程中有几点仍然需要特别注意. Tip 1:不要使用默认的"VS开发人员命令提示"工具,使用该工具会遭遇如下的错误: 正在创建库 gdal_i.l ...

  3. [BZOJ3456]城市规划:DP+NTT+多项式求逆

    写在前面的话 昨天听吕老板讲课,数数题感觉十分的神仙. 于是,ErkkiErkko这个小蒟蒻也要去学数数题了. 分析 Miskcoo orz 带标号无向连通图计数. \(f(x)\)表示\(x\)个点 ...

  4. 20165220课程设计个人报告——Part4-Cortex M4模块

    个人报告: 20165220 葛宇豪 1.个人贡献 a.实验环境搭建 b.代码分析与理解 2.设计中遇到的问题以及解决方案 问题1:mdk5每次编译之前都会直接闪退 刚开始以为是环境问题,后来上网查资 ...

  5. nginx回源使用localhost产生问题

    最近测试ngx_http_slice模块,回源的时候填的localhost结果老是超时,还以为是slice模块有问题,后来无意间改成127.0.0.1后就没有问题了 真是见鬼了 #user root; ...

  6. leetcode-mid-dynamic programming- Longest Increasing Subsequence-NO

    不会... 参考: 思路类似于coin那个题,for循环中在满足条件时就及时更新当下位置的信息 def lengthOfLIS(nums): """ :type nums ...

  7. P1364 医院设置 (补锅,memset初始化较大值不可用0x7fffffff )

    P1364 医院设置 题解 弗洛伊德水过 注意初始化一个大数 0x3f 可以,0x5f 好像也可以,但是0x7fffffff 我是真的炸了,初始化为-1 (后面补锅有详细解释) 代码 #include ...

  8. WAMP搭建与配置

    使用WampServer整合软件包进行WAMP环境搭建 WampServer是一款由法国人开发的Apache Web服务器.PHP解释器以及MySQL数据库的整合软件包.免去了开发人员将时间花费在繁琐 ...

  9. python是强类型还是弱类型语言

    几句话了解python特性 Python 是强类型的动态脚本语言 好多人对python到底是强语言类型还是弱语言类型存在误解,其实,是否是强类型语言只需要一句话就可以判别, 强类型:不允许不同类型相加 ...

  10. C# 开发COM组件供c++使用

    C# 开发COM组件供c++使用 Microsoft在解决和以往的COM和SDK开发技术之间的互操作性(Interoperability)方面做了很多的工作,其中包括COM和.NET对象之间的相互调用 ...