模仿combox(select)控件

select|控件

不用整天为美化select控件烦恼了。

运行代码框

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE> simulate combox control - http://www.never-online.net </TITLE><META NAME="Generator" CONTENT="EditPlus"><META NAME="Author" CONTENT=""><META NAME="Keywords" CONTENT=""><META NAME="Description" CONTENT=""><style>body, input{font-family: verdana;font-size: 9pt;}h1{font-family: tahoma;font-size: 22pt;text-align: left;}pre{font-size: 9pt;font-family: verdana;border: 1px solid #006600;width: 400px;padding: 10px;background: #ffffff;color: #006600;}.CtlSelect{border: 1px solid #006600;font-family: verdana;height: 20px;color: #006600;background: #ffffff;/*background:url({E5066804-650D-4757-9BA4-A92DB8817A18}0.jpg);*/}.selected{background: #006600;color: #ffffff;height: 20px;}.unselected{height: 20px;color: #006600;line-height: 120%;border-bottom: 1px solid #006600;}.CtlSelect1{border: 1px solid #003399;font-family: verdana;height: 20px;color: #003399;background: #ffffff;/*background:url({E5066804-650D-4757-9BA4-A92DB8817A18}0.jpg);*/}.selected1{background: #003399;color: #ffffff;height: 20px;}.unselected1{height: 20px;color: #003399;line-height: 120%;border-bottom: 1px solid #003399;}.CtlSelect2{border: 1px solid #990000;font-family: verdana;height: 20px;color: #990000;background: #ffffff;/*background:url({E5066804-650D-4757-9BA4-A92DB8817A18}0.jpg);*/}.selected2{background: #990000;color: #ffffff;height: 20px;}.unselected2{height: 20px;color: #990000;line-height: 120%;border-bottom: 1px solid #990000;}.copyright{margin-top: 10px;font-size: 9pt;text-align: center;color: #333;font-weight: bold;}</style></HEAD><BODY><SCRIPT LANGUAGE="JavaScript"><!--//-------------------------------------------------------------// @ Module: simulate select control, IE only.// @ Debug in: IE 6.0// @ Script by: blueDestiny, never-online// @ Updated: 2006-3-22// @ Version: 1.0 apha// @ Email: blueDestiny [at] 126.com// @ Website: http://www.never-online.net// @ Please Hold this item please.//// API// @ class: simulateSelect()//// @ object.style(ctlStyle[,selStyle][,unselStyle])// ctlStyle: main control combox css class name// selStyle: when mouseover or option focus css class name// unselStyle: options blur's css class name//// @ object.width=(widthPX)// widthPX must be a digit number.//// @ object.height=(heightPX)// heightPX must be a digit number.//// @ object.getValue(ctlSelID)// ctlSelID is the unique select control ID//// -------------- for the next Version ----------// @ object.readOnly = (blnReadOnly)// blnReadOnly must be a boolean type or a number type.// @ object.addEvent(w, h)// w: fire handler's event.// h: handler function.//-------------------------------------------------------------function $(objID){return document.getElementById(objID);};function Offset(e){var t = e.offsetTop;var l = e.offsetLeft;var w = e.offsetWidth;var h = e.offsetHeight-2;while(e=e.offsetParent){t+=e.offsetTop;l+=e.offsetLeft;}return {top : t,left : l,width : w,height : h}}//-----------------------------------------------function simulateSelect() { with(this){this.IDs = [];this.name = this;// property for beta Version// can editable comboxthis.readonly = true;this.height = 20;this.width = null;this.ctlStyle = "CtlSelect";this.selStyle = "selected";this.unselStyle = "unselected";this.elementPrefix = "e__";this.inputPrefix = "i__";this.containerPrefix = "c__";this.buttonPrefix = "b__";return this;}};simulateSelect.prototype.init = function(ctlSelIDs) { with(this){eval(name).append(ctlSelIDs);eval(name).simulates();}};simulateSelect.prototype.style = function() { with(this){ctlStyle = arguments[0];selStyle = arguments[1];unselStyle = arguments[2];}};//-----------------------------------------------simulateSelect.prototype.append = function(ctlSelIDs) { with(this){if( ctlSelIDs.indexOf(",")>0 ){var arrCtlSel = ctlSelIDs.split(",");for(var i=0; i<arrCtlSel.length; i++){eval(name).IDs.push(arrCtlSel[i]);}}else{eval(name).IDs.push(ctlSelIDs);}}};simulateSelect.prototype.checkupOnMouseDown = function(e) { with(this){// here compatible mf.var el = e ? e.srcElement : e.target;if( el.id.indexOf(elementPrefix)>-1 || el.id.indexOf(inputPrefix)>-1 || el.id.indexOf(containerPrefix)>-1 || el.id.indexOf(buttonPrefix)>-1 ){return;}else{for(var i=0; i<eval(name).IDs.length; i++)if( $(containerPrefix + IDs[i]) )$(containerPrefix + eval(name).IDs[i]).style.display = "none";}}};simulateSelect.prototype.simulates = function() { with(this){for(var i=0; i<IDs.length; i++)eval(name).simulate(IDs[i]);}};simulateSelect.prototype.simulate = function(ctlSelID) { with (this){var input;var button;var object;var offset;object = $(ctlSelID);offset = Offset(object);input = document.createElement("INPUT");button = document.createElement("BUTTON");button.setAttribute("id", buttonPrefix + ctlSelID);//button.value = "⊿";button.value = "6";button.style.fontFamily = "Webdings, Marlett";button.style.background = "";button.onclick = input.onclick = function(){this.blur();eval(name).expand(ctlSelID, offset);}input.onselectstart = function() { eval(name).expand(ctlSelID, offset); event.returnValue = false; };input.setAttribute("id", inputPrefix + ctlSelID);input.title = button.title = "click expand options";input.style.cursor = button.style.cursor = "default";input.className = button.className = ctlStyle;input.style.width = (width>0 ? width : object.offsetWidth);height ? input.style.height=button.style.height=height : "";input.value = object[0].text;if( readonly==true ) input.readOnly=true;// this method is only IE.object.insertAdjacentElement("afterEnd",button);object.insertAdjacentElement("afterEnd",input);object.style.display = 'none';}};simulateSelect.prototype.expand = function(ctlSelID, offset) { with(this){var div, btn_off;var object = $(ctlSelID);if( !$(containerPrefix + ctlSelID) ){div = document.createElement("DIV");div.style.position = "absolute";div.style.display = "block";div.setAttribute("id", containerPrefix + ctlSelID);div.className = ctlStyle;div.style.left = offset.left;div.style.top = offset.top + offset.height;div.style.width = (width ? width : offset.width) + 20;div.style.height = offset.height;document.body.appendChild(div);for(var i=0; i<object.length; i++){div = document.createElement("DIV");div.setAttribute("id", div.id = elementPrefix + ctlSelID + i);div.style.cursor = "default";if( object[i].text==$(inputPrefix + ctlSelID).value )div.className = selStyle;elsediv.className = unselStyle;div.innerText = div.title = object[i].text;div.style.height = height;div.setAttribute("value", object[i].value);div.onmouseover = function(){for(var j=0; j<$(containerPrefix + ctlSelID).childNodes.length; j++){if($(containerPrefix + ctlSelID).childNodes[j]==this)$(containerPrefix + ctlSelID).childNodes[j].className = selStyle;else$(containerPrefix + ctlSelID).childNodes[j].className = unselStyle;}};div.onclick = function(){$(inputPrefix + ctlSelID).value = this.innerText;$(containerPrefix + ctlSelID).style.display = "none";};$(containerPrefix + ctlSelID).appendChild(div);}return;}if( $(containerPrefix + ctlSelID).style.display=="none" ){for(var i=0; i<object.length; i++){if( object[i].text==$(inputPrefix + ctlSelID).value )$(elementPrefix + ctlSelID + i).className = selStyle;else$(elementPrefix + ctlSelID + i).className = unselStyle;}$(containerPrefix + ctlSelID).style.display="block";return;}if( $(containerPrefix + ctlSelID).style.display=="block" ){$(containerPrefix + ctlSelID).style.display="none";return;}}};simulateSelect.prototype.getValue = function(ctlSelID) { with(this){if( $(inputPrefix + ctlSelID) )return $(inputPrefix + ctlSelID).value;elsereturn null;}};simulateSelect.prototype.addEvent = function(w, h) { with(this){}};//-----------------------------------------------//window.onerror = Function("return true;");// IE only.document.attachEvent("onmousedown", function() {a.checkupOnMouseDown(event);b.checkupOnMouseDown(event);c.checkupOnMouseDown(event)});//--></SCRIPT><h1> simulate combox control </h1><h4> demonstrate </h4><p><select id="s0"><option value="- please select your options -"> - please select your options -</option><option value="1">option1</option><option value="2">option2</option><option value="3">option3</option><option value="4">option4</option><option value="5">option5</option></select></p><p><select id="s1"><option value="- please select your options -"> - please select your options -</option><option value="1">1option1</option><option value="2">1option2</option><option value="3">1option3</option><option value="4">1option4</option><option value="5">1option5</option></select></p><p><select id="s2"><option value="- please select your options -"> - please select your options -</option><option value="1">2option1</option><option value="2">2option2</option><option value="3">2option3</option><option value="4">2option4</option><option value="5">2option5</option></select></p><p><select id="s3"><option value="- please select your options -"> - please select your options -</option><option value="1">3option1</option><option value="2">3option2</option><option value="3">3option3</option><option value="4">3option4</option><option value="5">3option5</option></select></p><button class="CtlSelect"> Get value </button><SCRIPT LANGUAGE="JavaScript"><!--var a = new simulateSelect();a.style("CtlSelect", "selected", "unselected");a.init("s1");var b = new simulateSelect();b.style("CtlSelect1", "selected1", "unselected1");b.width = 300;b.init("s2");var c = new simulateSelect();c.style("CtlSelect2", "selected2", "unselected2");c.width = 320;c.init("s3");//--></SCRIPT><h4> description </h4><pre>//-------------------------------------------------------------// @ Module: simulate select control, IE only.// @ Debug in: IE 6.0// @ Script by: blueDestiny, never-online// @ Updated: 2006-3-22// @ Version: 1.0 apha// @ Email: blueDestiny [at] 126.com// @ Website: http://www.never-online.net// @ Please Hold this item please.//// API// @ simulateSelect(ctlSelIDs)// ctlSelIDs: select control IDs, split by ","//// @ simulateSelect.style(ctlStyle[,selStyle][,unselStyle])// ctlStyle: main control combox css class name// selStyle: when mouseover or option focus css class name// unselStyle: options blur's css class name//// @ simulateSelect.width=(widthPX)// widthPX must be a digit number.//// @ simulateSelect.height=(heightPX)// heightPX must be a digit number.//// -------------- for the next Version ----------// @ simulateSelect.readOnly = (blnReadOnly)// blnReadOnly must be a boolean type or a number type.// @ simulateSelect.addEvent(w, h)// w: fire handler's event.// h: handler function.//-------------------------------------------------------------</pre><div class="copyright">Power By blueDestiny, never-onlinehttp://www.never-online.net</div></BODY></HTML>

    [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

时间: 2024-09-17 03:41:36

模仿combox(select)控件的相关文章

模仿combox(select)控件 省去美化烦恼

select|控件 不用整天为美化select控件烦恼了. 1.可批量美化select控件. 2.可以有onchange句柄. 3.触发onchange的函数可带参数. 3.可以得到select的值. 4.可设置像select类似的滚动条(如大于或等于8个数目时出现滚动条) 5.可设置宽度和高度 API参考: //首先生成一个simulateSelect的实例 //构造函数的第一个可选参数为触发onchange的函数,其它的为onchange函数的参数; c = new simulateSele

模仿combox(select)控件,不用为美化select烦恼了。_经验交流

simulate combox control demonstrate normal select: - please select your options -option1option2option3option4option5 simulate select: - please select your options -1option11option21option31option41option5 scroll simulate select: - please select your

select控件在Mozilla和Opera中的问题

select|控件|问题 1. Mozilla和Opera都不支持该字体,改掉DTD也是没有效果.测试在Mozilla Firefox1.5, Opera9.0下都是显示成Arial字体.而特殊符号是支持的. 如:<body id="www.never-online.net"> <div style="font-family:Webdings">6</div> <div>▼</div> </body&

div模拟下拉菜单select控件模块 css实现表单select美化

     div css模拟实现form表单下拉select控件美化与功能实现.可以实现模拟的select表单下拉提交数据传值功能     使用方法与调用方式:$.divselect("#divselect","#inputselect"); "#divselect" 这是哪个模拟列表的盒子的ID,"#inputselect"这个是选择以后给 id="inputselect" 的input隐藏域赋值的哦.

IE6下div层被select控件遮住的问题解决方法

IE6下层被select控件遮住的问题想必大家在布局过程中都有遇到过吧,其实解决方法很简单就是在层里套个iframe,具体实现如下,感兴趣的朋友可以参考下,希望对大家有所帮助   这个应该在网上有很多解决的办法,只不过很多问题解决了之后就忘了,之后遇到了再去找有时就找不到了,就当给自己做个笔记了 方法很简单在层里套个iframe <div>能看见我了吗?<iframe frameborder="0" ></iframe></div> 有一

jquery下拉select控件操作方法分享

 这篇文章主要介绍了jquery下拉select控件操作方法分享(jquery操作select),需要的朋友可以参考下 JQuery获取和设置Select选项方法汇总如下:   代码:   代码如下: $("#select_id").change(function(){//code...});   //为Select添加事件,当选择其中一项时触发 var checkText=$("#select_id").find("option:selected&quo

javascript-js中使用select控件时需要加上form吗?

问题描述 js中使用select控件时需要加上form吗? 在页面中,有表单form1 里面有一个select控件 名称为category.而在js中设置select时,如果document.category.options[tt]=new Option(""""");就无法创建成功. 但是使用document.form1.category.options[tt]=new Option(""""");就可以

轻松使用jQuery双向select控件Bootstrap Dual Listbox_jquery

本文主要为大家介绍了双向select控件Bootstrap Dual Listbox的使用方法,Bootstrap Dual列表是一个为响应Twitter优化的列表框插件,它可以用在所有的现代浏览器和触摸设备上,分享给大家,具体如下: 效果图: 一.使用 1.引用css和js文件 <link href="scripts/bootstrap-3.3.5-dist/css/bootstrap.min.css" rel="stylesheet" /> <

HTML的select控件美化

原文:HTML的select控件美化 HTML的select控件美化 CSS: .div-select { border: solid 1px #999; height: 40px; line-height: 40px; cursor: default; } .div-select-text { float: left; background-color: #fff; height: 100%; word-break: keep-all; overflow: hidden; cursor: de