select发展史 超强第1/2页
作者:marvellous
本文旨在大家对select和模拟select有一个全面地了解,使此项技术能发挥出更高的水平。
最初的select的确很平淡,就是一个下拉选项列表:
select,option {background-color:lime}
1
2
不是一样的嘛
select,option {background-color:lime;font-family:华文行楷;color:red;}
上海
北京
香港
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
日久天长之后,人们对select要求高了,要修一修边幅:
i=1;
11111 111111 111111111111
2222222
333333
4444444
=document.form1.select01.options.length){i=0}document.form1.select01.options[i].selected=true;i++">q
Untitled Document
.table1{background-color:white;FONT-FAMILY: Courier New, Courier;font-size:12px}
.td_out{FONT-FAMILY: Courier New, Courier;font-size:12px;color:#000000;height:15px;border:1 solid #ffffff;}
.td_over{FONT-FAMILY: Courier New, Courier;font-size:12px;cursor:default;background-color:#3366cc;border:1 solid #000000;color:#ffffff;height:15px}
.slv{vertical-align:bottom;FONT-FAMILY: Courier New, Courier;font-size:12px;border-left-width:0;border-top-width:0;border-bottom-width:0;border-right:0 solid #000000;vertical-align:middle;height:18px;color:#000000;}
.down{position:relative;left:-2px;font-size:11px;vertical-align:middle;width:16;height:16;color:#2050b0;background-color:#D0DFF7;border:1 solid #9fA3Ce;writing-mode:tb-rl;font-weight:bold;
}
.seldiv{
position:absolute;z-index:1000;overflow-x:hidden;border-left:1 solid #000000;border-bottom:1 solid #000000;border-right:1 solid #000000;
SCROLLBAR-FACE-COLOR: #d0dff7;
SCROLLBAR-HIGHLIGHT-COLOR: #d0dff7;
SCROLLBAR-SHADOW-COLOR: #FFFFFF;
SCROLLBAR-3DLIGHT-COLOR: #FFFFFF;
SCROLLBAR-ARROW-COLOR: #ffffff;
SCROLLBAR-TRACK-COLOR: #ffffff;
SCROLLBAR-DARKSHADOW-COLOR: #d0dff7;}
document.onclick=hiddenDiv;
function getDivCount() {
var arr=document.all;
re=0;
for (i=0;i200){
sv.style.pixelHeight=200;
sv.style.overflowY='scroll';
}
else {
sv.style.pixelHeight=da.offsetHeight;
sv.style.overflowY='hidden';
}
}
function dropDown(ID){
var sv=document.all["ZfDiv_"+ID]
var tb=document.all["ZfData_"+ID]
if(sv.style.display=='none'){
sv.style.display='';
for(i=0;i'+v.Trim()+'';
c.onmouseover=new Function("over(this)");
c.onmouseout=new Function("out(this)");
c.onclick=new Function("setValue(this)");
c.className="td_out";
v='';
}
//增加inpnubox的接口,在页面中产生一个inputbox控件,下拉列表为空
function addText(name,DefValue) {
var i=getDivCount();
document.write('');
document.write('" onclick="this.hideFocus=true;dropDown('+i+');" class="down" onmouseover="this.style.backgroundColor=#EEF3FD" onmouseout="this.style.backgroundColor=\'\'" onmousedown="this.style.backgroundColor=#ABC4F5" onmouseup="this.style.backgroundColor=\'\'">');
document.write('
');
}
addText("name1","a");
add("1234",0);
add("1234",0);
addText("name1","a");
add("1234",1);
add("1234",1);
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
要加一些链接,变成菜单:
body { cursor: url(http://vip.6to23.com/candylau/image/xiucursor.cur)}
.select{border: 0 inset buttonface; width: 100; font: icon; cursor: default;}
.selected{border: 0 inset buttonface; background: window; padding: 0; font: icon;}
.selectTable{height: 100%; width: 100%;border: 2 inset buttonhighlight; background: buttonface;}
.option {font: icon; padding: 1; padding-left: 3; padding-right: 3; width: 100%;}
.dropDown{position: absolute; visibility: hidden; width: 100%;border: 1 solid windowtext; padding: 0;background: window;}
.select .button {width: 16px; height: 5; font-family: webdings; padding: 0;font-size: 11px; border: 2 outset buttonhighlight;}
var overOptionCss = "background: highlight; color: highlighttext";
var sizedBorderCss = "2 inset buttonhighlight";
var globalSelect;
var ie4 = (document.all != null);
var q = 0;
function initSelectBox(el) {
copySelected(el);
var size = el.getAttribute("size");
el.options = el.children[1].children;
el.selectedIndex = findSelected(el);
el.remove = new Function("i", "int_remove(this,i)");
el.item = new Function("i", "return this.options[i]");
el.add = new Function("e", "i", "int_add(this, e, i)");
el.options[el.selectedIndex].selected = true;
dropdown = el.children[1];
if (size != null) {
if (size > 1) {
el.size = size;
dropdown.style.zIndex = 0;
initSized(el);
}
else {
el.size = 1;
dropdown.style.zIndex = 99;
if (dropdown.offsetHeight > 200) {
dropdown.style.height = "200";
dropdown.style.overflow = "auto";
}
}
}
highlightSelected(el,true);
}
function int_remove(el,i) {
if (el.options[i] != null)
el.options[i].outerHTML = "";
}
function int_add(el, e, i) {
var html = "
";
if (e.text != null)
html += e.text;
html += "
"
if ((i == null) || (i >= el.options.length))
i = el.options.length-1;
el.options[i].insertAdjacentHTML("AfterEnd", html);
}
function initSized(el) {
var h = 0;
el.children[0].style.display = "none";
dropdown = el.children[1];
dropdown.style.visibility = "visible";
if (dropdown.children.length > el.size) {
dropdown.style.overflow = "auto";
for (var i=0; i\n';
str += '
\n'; str += '6 |
\n';
str += '
\n';
for (var i=0; i\n';
str += html;
str += '
\n';
}
str += '
\n';
str += '\n';
return str;
}
function createXString(matrix, id, size, onchange, css) {
var str = '\n';
str += '\n';
for (var i=0; i';
str += stripTags(html);
str += '\n';
}
str += '\n\n';
str += '\n';
return str;
}
function stripTags(str) {
var s = 0;
var e = -1;
var r = "";
s = str.indexOf("",s);
s = str.indexOf("
var optionArray = new Array();
optionArray[0] = new Option("Item 1", "value 1", "color: blue; text-decoration: underline;");
optionArray[1] = new Option("Item 2", "value 2");
optionArray[2] = new Option("Item 3", "value 3", "color: red;", "selected");
optionArray[3] = new Option("Item 4", "value 4");
optionArray[4] = new Option("Item 5", "value 5");
writeSelectBox(optionArray, "select1", 1, "alert(this.options[this.selectedIndex].value)", "margin-left: 10;");
writeSelectBox(optionArray, "select3", 3, "alert(this.options[this.selectedIndex].value)", "margin-left: 10;");
网易
google
搜狐
请选择颜色
红色
蓝色
绿色
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
var mmenus = new Array();
var misShow = new Boolean();
misShow=false;
var misdown = new Boolean();
misdown=false;
var musestatus=false;
var mpopTimer = 0;
mmenucolor='#396DA5';mfontcolor='#80FFFF';mmenuoutcolor='#396DA5';mmenuincolor='#9595FF';mmenuoutbordercolor='#00FFFF';mmenuinbordercolor='#000000';mmidoutcolor='#269DC3';mmidincolor='#26486E';mmenuovercolor='#FFFF00';mitemedge='1';msubedge='0';mmenuunitwidth=60;mmenuitemwidth=160;mmenuheight=30;mmenuwidth='300';mmenuadjust=0;mmenuadjustV=0;mfonts='font-family: Verdana; font-size: 8pt; color: #80FFFF; ';mcursor='default';
var swipeSteps = 4;
var swipemsec = 25;
var swipeArray = new Array();
function swipe(el, dir, steps, msec) {
if (steps == null) steps = swipeSteps;
if (msec == null) msec = swipemsec;
if (el.swipeIndex == null)
el.swipeIndex = swipeArray.length;
if (el.swipeTimer != null)
window.clearTimeout(el.swipeTimer);
swipeArray[el.swipeIndex] = el;
el.style.clip = "rect(-99999, 99999, 99999, -99999)";
if (el.swipeCounter == null || el.swipeCounter == 0) {
el.orgLeft = el.offsetLeft;
el.orgTop = el.offsetTop;
el.orgWidth = el.offsetWidth;
el.orgHeight = el.offsetHeight;
}
el.swipeCounter = steps;
el.style.clip = "rect(0,0,0,0)";
window.setTimeout("repeat(" + dir + "," + el.swipeIndex + "," + steps + "," + msec + ")", msec);
}
function repeat(dir, index, steps, msec) {
el = swipeArray[index];
var left = el.orgLeft;
var top = el.orgTop;
var width = el.orgWidth;
var height = el.orgHeight;
if (el.swipeCounter == 0) {
el.style.clip = "rect(-99999, 99999, 99999, -99999)";
return;
}
else {
el.swipeCounter--;
el.style.visibility = "visible";
switch (dir) {
case 2:
el.style.clip = "rect(" + height*el.swipeCounter/steps + "," + width + "," + height + "," + 0 + ")";
el.style.top = top - height*el.swipeCounter/steps;
break;
case 8:
el.style.clip = "rect(" + 0 + "," + width + "," + height*(steps-el.swipeCounter)/steps + "," + 0 + ")";
el.style.top = top + height*el.swipeCounter/steps;
break;
case 6:
el.style.clip = "rect(" + 0 + "," + width + "," + height + "," + width*(el.swipeCounter)/steps + ")";
el.style.left = left - width*el.swipeCounter/steps;
break;
case 4:
el.style.clip = "rect(" + 0 + "," + width*(swipeSteps - el.swipeCounter)/steps + "," + height + "," + 0 + ")";
el.style.left = left + width*el.swipeCounter/steps;
break;
}
el.swipeTimer = window.setTimeout("repeat(" + dir + "," + index + "," + steps + "," + msec + ")", msec);
}
}
var mtmpleft="";
var mtmptop="";
function hideSwipe(el) {
window.clearTimeout(el.swipeTimer);
el.style.visibility = "hidden";
el.style.clip = "rect(-99999, 99999, 99999, -99999)";
el.swipeCounter = 0;
if(mtmpleft!="")el.style.left = mtmpleft;
if(mtmptop!="")el.style.top = mtmptop;
}
function stoperror(){
return true;
}
window.onerror=stoperror;
function mpopOut() {
mpopTimer = setTimeout('mallhide()', 500);
}
function getReal(el, type, value) {
temp = el;
while ((temp != null) && (temp.tagName != "BODY")) {
if (eval("temp." + type) == value) {
el = temp;
return el;
}
temp = temp.parentElement;
}
return el;
}
function mMenuRegister(menu)
{
mmenus[mmenus.length] = menu
return (mmenus.length - 1)
}
function mMenuItem(caption,command,target,isline,statustxt,img,sizex,sizey,pos){
this.caption=caption;
this.command=command;
this.target=target;
this.isline=isline;
this.statustxt=statustxt;
this.img=img;
this.sizex=sizex;
this.sizey=sizey;
this.pos=pos;
}
function mMenu(caption,command,target,img,sizex,sizey,pos){
this.items = new Array();
this.caption=caption;
this.command=command;
this.target=target;
this.img=img;
this.sizex=sizex;
this.sizey=sizey;
this.pos=pos;
this.id=mMenuRegister(this);
}
function mMenuAddItem(item)
{
this.items[this.items.length] = item
item.parent = this.id;
this.children=true;
}
mMenu.prototype.addItem = mMenuAddItem;
function mtoout(src){
src.style.borderLeftColor=mmenuoutbordercolor;
src.style.borderRightColor=mmenuinbordercolor;
src.style.borderTopColor=mmenuoutbordercolor;
src.style.borderBottomColor=mmenuinbordercolor;
src.style.backgroundColor=mmenuoutcolor;
src.style.color=mmenuovercolor;
}
function mtoin(src){
src.style.borderLeftColor=mmenuinbordercolor;
src.style.borderRightColor=mmenuoutbordercolor;
src.style.borderTopColor=mmenuinbordercolor;
src.style.borderBottomColor=mmenuoutbordercolor;
src.style.backgroundColor=mmenuincolor;
src.style.color=mmenuovercolor;
}
function mnochange(src){
src.style.borderLeftColor=mmenucolor;
src.style.borderRightColor=mmenucolor;
src.style.borderTopColor=mmenucolor;
src.style.borderBottomColor=mmenucolor;
src.style.backgroundColor='';
src.style.color=mfontcolor;
}
function mallhide(){
for(var nummenu=0;nummenudocument.body.clientWidth+document.body.scrollLeft)
menuid.style.left=document.body.clientWidth+document.body.scrollLeft-mmenuitemwidth;
mtmpleft=menuid.style.left;mtmptop=menuid.style.top;swipe(menuid,8,4);
misShow=true;
}
function mmenu_over(menuid,x){
toel = getReal(window.event.toElement, "className", "coolButton");
fromel = getReal(window.event.fromElement, "className", "coolButton");
if (toel == fromel) return;
if(x==4){
misShow = false;
mallhide();
mtoout(eval("mMenu"+x));
}else{
if(!misShow){mtoout(eval("mMenu"+x));}else{
mallhide();
mtoin(eval("mMenu"+x));
mmenushow(menuid,eval("mMenu"+x));
}
}
}
function mmenu_out(x){
toel = getReal(window.event.toElement, "className", "coolButton");
fromel = getReal(window.event.fromElement, "className", "coolButton");
if (toel == fromel) return;
if (misShow){
mtoin(eval("mMenu"+x));
}else{
mnochange(eval("mMenu"+x));
}
}
function mmenu_down(menuid,x){
if(misShow){
mmenuhide(menuid);
mtoout(eval("mMenu"+x));
}
else{
mtoin(eval("mMenu"+x));
mmenushow(menuid,eval("mMenu"+x));
misdown=true;
}
}
function mmenu_up(){
misdown=false;
}
function mmenuitem_over(x,i){
srcel = getReal(window.event.srcElement, "className", "coolButton");
if(misdown){
mtoin(srcel);
}
else{
mtoout(srcel);
}
mthestatus = mmenus[x].items[i].statustxt;
if(mthestatus!=""){
musestatus=true;
window.status=mthestatus;
}
}
function mmenuitem_out(){
srcel = getReal(window.event.srcElement, "className", "coolButton");
mnochange(srcel);
if(musestatus)window.status="";
}
function mmenuitem_down(){
srcel = getReal(window.event.srcElement, "className", "coolButton");
mtoin(srcel)
misdown=true;
}
function mmenuitem_up(){
srcel = getReal(window.event.srcElement, "className", "coolButton");
mtoout(srcel)
misdown=false;
}
function mexec2(x){
var cmd;
if(mmenus[x].target=="blank"){
cmd = "window.open('"+mmenus[x].command+"')";
}else{
cmd = mmenus[x].target+".location=\""+mmenus[x].command+"\"";
}
eval(cmd);
}
function mexec(x,i){
var cmd;
if(mmenus[x].items[i].target=="blank"){
cmd = "window.open('"+mmenus[x].items[i].command+"')";
}else{
cmd = mmenus[x].items[i].target+".location=\""+mmenus[x].items[i].command+"\"";
}
eval(cmd);
}
function mbody_click(){
if (misShow){
srcel = getReal(window.event.srcElement, "className", "coolButton");
for(var x=0;x
for(var x=0;x"+ifspace+thismenu.caption+"
";
}else if(thismenu.pos=="1"){
stringx += " align=center>"+thismenu.caption+ifspace+"
";
}else if(thismenu.pos=="2"){
stringx += " align=center background='"+thismenu.img+"'> "+thismenu.caption+"
";
}else{
stringx += " align=center> "+thismenu.caption+"
";
}
stringx += "";
}
stringx+="
";
for(var x=0;x
';
}else{
stringx+='
\n'+
'
"+ifspace+thismenuitem.caption+" |
\n
'
}
}
document.write("
"+stringx+"
");
}
function mcheckLocation(){
if(isNaN(mmenuwidth))mmenuwidth=document.body.clientWidth*parseInt(mmenuwidth.substring(0,3))/100;ym=eval(document.body.scrollTop)+document.body.clientHeight-mmenuheight-10;xm=eval(document.body.scrollLeft)+10;y=mmenutable.style.pixelTop;x=mmenutable.style.pixelLeft;if(Math.abs(ym-y)>1)mmenutable.style.pixelTop=y+=(ym-y)/5;else mmenutable.style.pixelTop=y=ym;if(Math.abs(xm-x)>1)mmenutable.style.pixelLeft=x+=(xm-x)/5;else mmenutable.style.pixelLeft=x=xm;setTimeout("mcheckLocation()",10);}
mpmenu1=new mMenu('File','','self','','','','');
mpmenu1.addItem(new mMenuItem('New','javascript:alert(\\"New\\")','self',false,'New','','','',''));
mpmenu1.addItem(new mMenuItem('Open','javascript:alert(\\"Open\\")','self',false,'Open','','','',''));
mpmenu1.addItem(new mMenuItem('Save','javascript:alert(\\"Save\\")','self',false,'Save','','','',''));
mpmenu1.addItem(new mMenuItem(null,null,null,true));
mpmenu1.addItem(new mMenuItem('Exit','javascript:alert(\\"Exit\\")','self',false,'Exit','','','',''));
mpmenu2=new mMenu('Edit','','self','','','','');
mpmenu2.addItem(new mMenuItem('Undo','javascript:alert(\\"Undo\\")','self',false,'Undo','','','',''));
mpmenu2.addItem(new mMenuItem('Forward','javascript:alert(\\"Forward\\")','self',false,'Forward','','','',''));
mpmenu2.addItem(new mMenuItem(null,null,null,true));
mpmenu2.addItem(new mMenuItem('Copy','javascript:alert(\\"Copy\\")','self',false,'Copy','','','',''));
mpmenu2.addItem(new mMenuItem('Paste','javascript:alert(\\"Paste\\")','self',false,'Paste','','','',''));
mpmenu3=new mMenu('Favorites','','self','','','','');
mpmenu3.addItem(new mMenuItem('My Homepage','http://www.KnifeSoft.com','blank',false,'Visit My Homepage','','','',''));
mpmenu3.addItem(new mMenuItem('Yahoo','http://www.yahoo.com','blank',false,'Visit Yahoo','','','',''));
mpmenu4=new mMenu('Help','','self','','','','');
mpmenu4.addItem(new mMenuItem('Contect','javascript:alert(\\"Contect\\")','self',false,'Contect','','','',''));
mpmenu4.addItem(new mMenuItem('Send me an email','mailto:support@knifesoft.com','self',false,'Send me an email.','','','',''));
mpmenu4.addItem(new mMenuItem(null,null,null,true));
mpmenu4.addItem(new mMenuItem('About','javascript:alert(\\"About\\")','self',false,'About WebMenuShop','','','',''));
mpmenu4=new mMenu('KnifeSoft','http://www.knifesoft.com','self','','','','');
mwritetodocument();
mcheckLocation();
产品快速导航 多媒体产品 DLP数字光显背投 LCD液晶电视 数字高清背投 PDP等离子电视 CRT高清彩电 酒店电视 乐华彩电 视盘机 监视器 电视墙 通讯产品 手机 电话机 网络设备 宽带产品 数码产品 家用电脑 商用电脑 笔记本电脑 DV产品 MP3播放器 MP4播放器 家电产品 电冰箱 洗衣机 空调 中央空调 电饭煲 电磁炉 电风扇 饮水机 电暖器 净水器 烧烤炉 电气产品 开关插座 照明产品 工业电器 智能楼宇 部品产品 集成电路 高频头 电池 文化产品 美卡音像 TCL光盘
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
后来发展到其文字内容可以增、删、编、改,即可以编辑:
EditSelect
function isIE(){
a=navigator.appVersion.split(";")
b=a[1].split(" ")
return parseFloat(b[2])
}
if (isIE()
selectáD表
'
}
else
{
scHTML='
selectáD表
'
}
document.write(scHTML)
vDiv=selectcontent
vDivHtml=selecthtml
function editselect(name,size,defaulttext,width,height,readonly){
var combo=this;
this.options=new Array();
this.oj=new Array();
this.name=name;
this.divname=name+'_div';
this.buttonname=name+'_button';
this.tablename=name+'_table';
this.htmltable=name+'_html'
if (!height) this.height=0; else this.height=height
if (width) this.width=width
if (!size) size=8
if (!defaulttext) defaulttext=""
if (!readonly || readonly==0) {readonly="" }else {if (readonly==1) readonly="readonly style=cursor:default";this.readonly=1}
esHTML='
'
+'
' +' | 6 |
'
+'
'
document.write(esHTML)
this.sbutton=eval("document.all."+this.buttonname)
if (this.readonly==1) eval("document.all."+this.name).onclick=function(){combo.show()}
this.sbutton.onclick=function(){combo.show()}
this.show=function(){
pDiv=eval(combo.divname)
pTable=eval(combo.tablename)
var vHTML='
'+combo.options[i] } vHTML+=" |
"
vDivHtml.innerHTML=vHTML
vtop=pDiv.offsetTop+pDiv.offsetHeight
vleft=pDiv.offsetLeft+2
vParent = pDiv.offsetParent;
while (vParent.tagName.toUpperCase() != "BODY")
{
vleft += vParent.offsetLeft;
vtop += vParent.offsetTop;
vParent = vParent.offsetParent;
}
var redge=document.body.clientWidth-vleft
var bedge=document.body.clientHeight-vtop
if (!combo.width) {vDiv.style.width=pTable.offsetWidth} else {vDiv.style.width=combo.width}
if (combo.height==0)
{
vDiv.style.pixelHeight=parseInt(htmltable.offsetHeight)+2
vDivHtml.style.pixelHeight=parseInt(htmltable.offsetHeight)+2
}
else
{
if (htmltable.offsetHeight>combo.height)
{
vDiv.style.pixelHeight=combo.height
vDivHtml.style.pixelHeight=combo.height
}
else
{
vDiv.style.pixelHeight=parseInt(htmltable.offsetHeight)+2
vDivHtml.style.pixelHeight=parseInt(htmltable.offsetHeight)+2
}
}
vDivHtml.scrollTop=0
if (redge
.selecttext{
border:0px
height: 16;
font-family:arial;
font-size:12px;
}
.selectbutton{
font-family:webdings;
font-size:10px;
height: 19;
width: 16;
border:1px solid #83A5EB;
line-height:0px;
padding-bottom:3px;
background-color:#D1E0FD
}
.selecttable{
font-family:arial;
font-size:12px;
cursor:default;
}
.selectcontent
{
position: absolute;
top:0;
left:0;
overflow:auto;
border:1px solid #000000
}
.selectdiv
{
position: absolute;
width:100;
overflow:hidden;
}
.select{
border-collapse: collapse;
border:1px solid #7F9DB9
}
可编辑的Select |
var sel1=new editselect("select1","25","可编辑的Select",""); sel1.add("这是一个可以编辑的Select") sel1.add("支持CSS") sel1.add("可以通过CSS,修改外形") sel1.add("突破原来的Select诸多限制") |
长度可以随意修改 可以设置为只读 |
var sel2=new editselect("select2","20","长度可以随意修改",250,82,1); sel2.add("这是一个可以编辑的Select") sel2.add("支持CSS") sel2.add("可以通过CSS,修改外形") sel2.add("作者:舜子制作") |
可以遮盖系统Select |
var sel3=new editselect("select3","25","可以遮盖系统Select","",41); sel3.add("这是一个可以编辑的Select") sel3.add("支持CSS") sel3.add("可以通过CSS,修改外形") sel3.add("突破原来的Select诸多限制") |
系统的Select |
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
当前1/2页 12下一页阅读全文