解决IE浏览器下select下拉框默认样式问题
来源:互联网 发布:游戏测试软件 编辑:程序博客网 时间:2024/05/17 16:02
在项目中,某个页面由于监控控件需要在IE上运行,导致IE上select下拉框无法清除样式,影响美观。
以css解决,出现以下问题:
1. select的默认样式清除,appearance:none,background:transparent;无法清除下拉箭头;
2. 在外层用div定宽使用overflow:hidden;将白色下拉框隐藏, 无奈点击select后,option框会上移,并且选中后option背景会盖住select背景图片,导致背景图片无效;
解决办法,使用js模拟select效果
html<div class="box"> <div class="problem"></div> <ul class="item-wrap"></ul></div><div class="showMsg"></div>
css*{ margin: 0; padding: 0;}li{ list-style: none;}.box{ width: 266px; height: 43px; position: absolute; top: 50px; left: 100px;}.problem{ width: 266px; height: 43px; line-height: 43px; background: url(images/selectbg_266.png) no-repeat; color: #ffffff; position: relative; top: 0; left: 0; text-indent: 10px;}.item-wrap{ width: 266px; background: #013768; line-height: 30px; position: absolute; top: 42px; left: 0; display: none;}.item-wrap li{ color: #ffffff; text-indent: 10px;}.item-wrap li:hover{ background: #269ABC;}.item-wrap li:nth-of-type(even){ background: #013796;}
json数据[{"deptId":10001,"deptName":"选项一"},{"deptId":10002,"deptName":"选项二"},{"deptId":10003,"deptName":"选项三"},{"deptId":10004,"deptName":"选项四"},{"deptId":10005,"deptName":"选项五"}]
jsvar oUl=$(".item-wrap");$.ajax({ url:'js/data.json', type:'GET', dataType:'json', success:function(result){ for(var i=0;i<result.length;i++){ var oli = "<li value="+'"'+result[i].deptId+'"'+">"+result[i].deptName+"</li>"; oUl.append(oli); } var checkedId=$('.item-wrap li[value="10004"]').attr("value");//按照需求选择预设值 var checkName=$('.item-wrap li[value="10004"]').text(); if(checkedId!=""){//若满足条件,取预设值 $(".problem").text(checkName); $(".showMsg").html(checkedId);//预设id(调用函数) }else{//否则选中第一项 var name=$($(".item-wrap").children("li").get(0)).text(); $(".problem").text(name); } }});$(".problem").click(function(e){ $(".item-wrap").fadeToggle(100); e.stopPropagation();});//下拉框功能实现$(".item-wrap").on("click","li",function(e){ var checkVal=$(this).text(); var deptId=$(this).attr("value");//获取id(调用函数) $(".showMsg").html(deptId); console.log(deptId); $(".problem").text(checkVal);//div赋值 $(".item-wrap").fadeOut(); e.stopPropagation();});
还原项目使用场景:
1. 使用ajax获取数据
2. 有预设值
3. 动态取得编号id
0 0
- 解决IE浏览器下select下拉框默认样式问题
- select下拉框在IE和火狐下样式问题
- ie下select默认样式修改
- 取消 select 下拉框默认样式
- 关于select下拉框样式修改问题
- select下拉框之默认选中问题
- 改变html默认select下拉框的样式
- css改变下拉列表select框的默认样式
- 去除select下拉框默认样式以及一些兼容问题
- HTML中select下拉框默认样式修改
- 【CSS修改下拉选框select的默认样式】
- 去除select框的默认样式 (包括下拉尖括号)
- 解决IE浏览器不支持CSS样式呈现的问题
- IE和FF浏览器的默认样式
- IE下Select下拉框宽度无法自适应Bug
- 解决IE下select innerHTML无效的问题
- 下拉框select样式改写
- select下拉框默认选择
- 设计模式练习(8)——组合模式
- tcp time_wait 状态存在的原因
- 我的2014,读多学少,想多做少
- 安卓通讯之《蓝牙单片机通讯助手》②扫描设备、连接设备和双向通讯。
- C语言--链表的销毁
- 解决IE浏览器下select下拉框默认样式问题
- idea上传项目到github上面
- Codeforces Round #392 (Div. 2)
- Android多媒体技术(二)浅析Camera视频实时采集中涉及的参数配置
- Android实现WebActivity初始化一次
- 面向业务的立体化高可用架构设计
- C# windows服务
- jzoj C组 2017.1.20 比赛
- Bootstrap table 分页,排序,搜索 记录