100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > javascript模拟select实现代码_表单特效

javascript模拟select实现代码_表单特效

时间:2019-12-20 18:41:00

相关推荐

javascript模拟select实现代码_表单特效

web前端|js教程

javascript,select

web前端-js教程

最近迷茫于javascript的闭包与继承,写一个小东西找找感觉。

三端平台源码,ubuntu如何手动升级,爬虫英文水平,兴趣部落php,seo韩国明星lzw

JS+CSS模拟Select下拉框,选择表单效果

360建站系统源码,投屏软件 ubuntu,2个tomcat改端口,python爬虫后台,php代码在哪里运行,庐江seolzw

网页中使用Select语法实现的下拉框是很普遍的,但是您有没有见过使用JS+CSS模拟的Select下拉框?并且可以选择表单哦,尽管代码复杂了点,但是对于我们了解此类特效非常有帮助。

j2ee应用开发源码,vscode 隐藏缩略图,ubuntu无效主题,tomcat默认部署配置,爬虫任务图谱,php变长参数,全网seo推广有用吗,小说合作网站源,微赞如何安装pc模板lzw

DIV+CSS+JS仿下拉表单function $$$$$(_sId){ return document.getElementById(_sId); } function hide(_sId) {$$$$$(_sId).style.display = $$$$$(_sId).style.display == “none” ? “” : “none”;} function pick(v) { document.getElementById(‘am’).value=v; hide(‘HMF-1’) } function bgcolor(id){ document.getElementById(id).style.background=”#F7FFFA”; document.getElementById(id).style.color=”#000″; } function nocolor(id){ document.getElementById(id).style.background=””; document.getElementById(id).style.color=”#788F72″; } * { margin:0px; padding:0px; } body { font-family: Arial, Helvetica, sans-serif; font-size: 12px; } .cur { cursor:pointer; display:block; color:#788F72; width:71px; height:22px; line-height:22px; padding:0px 0px 0px 2px; } .am { border: 0px; color:#788F72; cursor: pointer; background: url(/uploads/allimg/1111/icon_111.jpg) no-repeat center center; border:1px #ccc solid; display:block; cursor:pointer; width:73px; height: 19px; margin:10px 0px 0px 10px; padding:3px 0px 0px 2px; } .bm { border: 1px #999999 solid; width:73px; margin-left:10px; }

测试一 测试二 测试三 测试四 测试五 测试六

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]这个作品在没有任何需求下完成,不保证能应用于实际应用,仅用于自娱自乐。

浏览器默认样式

select1select2select3select4

js模拟select,样式主要参照IE8与Firefox。

select1

select2

select3

select4

在不改变HTML结构的前提下,可更改其它样式。建议用IE8与FF浏览,可与默认样式进行对比。

// <![CDATA[ function beginSelect(elem){ if(elem.className == "btn"){ elem.className = "btn btnhover" elem.onmouseup = function(){ this.className = "btn" } } var ul = elem.parentNode.parentNode; var li = ul.getElementsByTagName("li"); var selectArea = li[li.length-1]; if(selectArea.style.display == "block"){ selectArea.style.display = "none"; } else{ selectArea.style.display = "block"; mouseoverBg(selectArea); } } function mouseoverBg(elem1){ var input = elem1.parentNode.getElementsByTagName("input")[0]; var p = elem1.getElementsByTagName("p"); var pLength = p.length; for(var i = 0; i < pLength; i++){ p[i].onmouseover = showBg; p[i].onmouseout = showBg; p[i].onclick = postText; } function showBg(){ this.className == "hover"?this.className = " ":this.className = "hover"; } function postText(){ var selected = this.innerHTML; input.setAttribute("value",selected); elem1.style.display = "none"; } } // ]]>

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]用js模拟实现表单select选择的功能

用js模拟实现表单select选择的功能.t_search {width:900px; margin:auto;} .t_s_item {width:100px; float:left;} /* s_select start */ .select_box {cursor:default; text-align:left;} .select_value {border:1px solid; filter:alpha(opacity:0); visibility:hidden; overflow-x:hidden; overflow:auto; position:absolute;} .select_record0 {padding-left:4px; background:#fff; width:100%; color:#000; height:20px; line-height:20px;} .select_record1 {padding-left:4px; background:#ccc; width:100%; color:#000; height:20px; line-height:20px;} /* s_select end */

/* s_search start */ var sortname; var age; var addr; var keywords; var dropShow=false; var currentID; function dropdown(el){ if(dropShow){ dropFadeOut(); }else{ currentID=document.getElementById(el); currentID.style.visibility=”visible”; dropFadeIn(); } } function dropFadeIn(){//选单淡入的效果 if(currentID.filters.alpha.opacity0){ clearTimeout(fadeTimer); currentID.filters.alpha.opacity-=20; fadeTimer=setTimeout(“dropFadeOut()”,50); }else{ dropShow=false; currentID.style.visibility=”hidden”; } } function dropdownHide(){ if(dropShow){ dropFadeOut(); dropShow=false; } } function hiLight(el){//高亮度显示指标位置 if(dropShow){ for(i=0;i= 0){tempTxt=el.innerText.replace(“┝”,””);} document.getElementById(“text”).innerText=tempTxt.substring(0,tempTxt.indexOf(“|”)); tempstr=tempTxt.substring(tempTxt.indexOf(“|”)+1); } function CheckMe1(el){//替换显示内容 document.getElementById(“text1”).innerText=el.innerText; sortname=el.innerText; } function CheckMe2(el){//替换显示内容 document.getElementById(“text2”).innerText=el.innerText; age=el.innerText; } function CheckMe3(el){//替换显示内容 document.getElementById(“text3”).innerText=el.innerText; addr=el.innerText; } document.onclick=dropdownHide; function go_search(){ keywords=document.getElementById(“form_search”).keywords.value; if(!sortname){sortname=””;} if(!age){age=””;} if(!addr){addr=””;} if(keywords==”请输入你要找的信息!”){keywords=””;} location.href=”userlist.php?sortname=”+sortname+”&age=”+age+”&addr=”+addr+”&keywords=”+keywords; } /* s_search end */

类别1

类别2

类别3

18-25岁

26-32岁

上海

浙江

福建

广东

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]在不改变HTML结构的前提下,可更改其它样式。建议用IE8与FF浏览,可与默认样式进行对比。

发布一来是为了记录自己学习过程,二来想请朋友指点一下迷津,哪些地方欠妥或者有更好的思路可以给我指点一下,谢谢。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。