📄 control.js
字号:
// size: size of dropdownlist;
// return: dropDownList Object
// ------------------------------------------------------------------
// dropDownList object:
// method: Enable()
// Disable()
// setValue(text)
// add(text,value) (String to be displayed, the value of the text)
// property: isEnable
// value selected value
// event: onChange
//
/////////////////////////////////////////////
var downListCreator=function()
{
this.ranId="ID"+parseInt(Math.random()*100000)+"_"+parseInt(Math.random()*100000);
var scriptDiv=document.createElement("div");
scriptDiv.id=this.ranId;
scriptDiv.style.display="none";
document.body.appendChild(scriptDiv);
this.getCtrl=function(arrList,ctrlName,ctrlParentNode,dftVal,size)
{
var haveMatchVar=false;
this.listValue=arrList;
this.ctrlName=ctrlName;
var tmpArr=new Array();
var scriptElement=document.createElement("script");
scriptElement.language="javascript";
var innerText1='var downlist_'+this.ctrlName+'=new editselect("'+this.ctrlName+'","'+size+'","'+dftVal+'",false,100,1,"'+ctrlParentNode+'");';
// dftVal=dftVal.replace(/+/g,"\+");
dftVal=dftVal.replace(/([^a-zA-Z0-9\s])/g,"\\$1");
eval("var expStr=/^"+dftVal+"\\|/;")
//alert(expStr)
//alert("dododo|2".match(expStr)==null)
for (i=0;i<arrList.length;i++)
{
tmpArr=arrList[i].split("|");
innerText1+='downlist_'+this.ctrlName+'.add("'+tmpArr[0]+'","'+tmpArr[1]+'");'
//alert(expStr);
if (arrList[i].match(expStr)!=null)
{
//alert("kaokao");
scriptElement.value=tmpArr[1];
haveMatchVar=true;
}
}
if (!haveMatchVar)
{
scriptElement.value="";
}
scriptElement.text=innerText1
document.getElementById(this.ranId).appendChild(scriptElement);
scriptElement.Enable=this.dlEnableFunction(this.ctrlName,scriptElement)
scriptElement.Disable=this.dlDisableFunction(this.ctrlName,scriptElement);
scriptElement.setValue=this.getSetValueFunction(this.ctrlName,scriptElement,arrList);
scriptElement.setText=this.getSetTextFunction(this.ctrlName,scriptElement,arrList);
scriptElement.add=this.getAddFunction(this.ctrlName,scriptElement,arrList);
scriptElement.isEnable=true;
scriptElement.onChange=function(){}
scriptElement.id="downlist_script_"+this.ctrlName
return scriptElement;
}
this.dlEnableFunction=function(name,scObj)
{
return function()
{
scObj.isEnable=true;
var dlObj=eval("downlist_"+name)
dlObj.Enable();
}
}
this.dlDisableFunction=function(name,scObj)
{
return function()
{
scObj.isEnable=false;
var dlObj=eval("downlist_"+name)
dlObj.Disable();
}
}
this.getSetValueFunction=function(name,scObj,arrList)
{
return function(newValue)
{
var tmpArr;
eval("var expStr=/^"+newValue+"\\|/;")
for (i=0;i<arrList.length;i++)
{
if (arrList[i].match(expStr)!=null)
{
tmpArr=arrList[i].split("|");
scObj.value=tmpArr[1];
document.getElementById(name+"_button_input").value=newValue;
return;
}
}
}
}
this.getSetTextFunction=function(name,scObj,arrList)
{
return function(newValue)
{
var tmpArr;
eval("var expStr=/\\|"+newValue+"$/;")
for (i=0;i<arrList.length;i++)
{
if (arrList[i].match(expStr)!=null)
{
tmpArr=arrList[i].split("|");
scObj.value=tmpArr[1];
document.getElementById(name+"_button_input").value=tmpArr[0];
return;
}
}
}
}
this.getAddFunction=function(name,scObj,arrList)
{
return function(text,value)
{
var dlObj=eval("downlist_"+name);
dlObj.add(text,value);
arrList.push(text+"|"+value)
}
}
}
scHTML='<div id="selectcontent" class="selectdiv" style="visibility:hidden;"><div id="selecthtml" class="selectcontent">select</div></div>'
document.write(scHTML)
vDiv=selectcontent
vDivHtml=selecthtml
function editselect(name,size,defaulttext,width,height,readonly,parentNodeName)
{
this.Enable=function()
{
this.enable=true;
document.getElementById(this.buttonname+"_input").className="selecttext"
document.getElementById(this.buttonname).className="selectbutton"
}
this.Disable=function()
{
this.enable=false;
document.getElementById(this.buttonname+"_input").className="selecttextdis"
document.getElementById(this.buttonname).className="selectbuttondis"
}
var combo=this;
this.options=new Array();
this.name=name;
this.divname=name+'_div';
this.buttonname=name+'_button';
this.tablename=name+'_table';
this.htmltable=name+'_html';
this.hasFirstDropDown=false;
this.enable=true;
this.selectedIndex=0;
this.hightLightValue="";
this.excusiveId="BT_"+Math.floor(Math.random(100)*10000)+"_"+Math.floor(Math.random(100)*10000);
this.previousSelectId=0;
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='<div id='+this.divname+'>'
+'<table id='+this.tablename+'><tr><td valign="bottom">'
+'<input type=text id="'+this.buttonname+'_input" class="selecttext" size="'+size+'" name='+name+' value="'+defaulttext+'" '+readonly+'><span onfocus="" tabindex="-1" class=selectbutton id='+this.buttonname+' /></td></tr></table>'
+'</div>'
var parentNodeObject=document.getElementById(parentNodeName);
if (parentNodeObject==null)
{
document.write(esHTML)
}
else
{
parentNodeObject.innerHTML=esHTML;
}
document.getElementById(this.buttonname).onblur=document.getElementById(this.buttonname+'_input').onblur=function()// When lose focus, hide the drop down list
{
//document.getElementById("selectcontent").style.visibility="hidden";
}
this.sbutton=eval("document.all."+this.buttonname)
this.subInputBox=null;
this.subInputBox=document.getElementById(this.buttonname+'_input');
if (this.readonly==1) this.subInputBox.onclick=function()
{
if (document.getElementById("selectcontent").style.visibility!="hidden")
{
return;
}
combo.show(1)
}
this.getKeydownFunction=function(obj)
{
return function()
{
if (event.keyCode==27 || event.keyCode==9)// user press "esc" key or "tab" key;
{
document.getElementById("selectcontent").style.visibility="hidden";
}
if (event.keyCode==40)// user press "down" key
{
obj.selectedIndex++;
if(document.getElementById("selectcontent").style.visibility=="hidden")
{
obj.selectedIndex=1;
}
if(obj.options.length<obj.selectedIndex)
{
obj.selectedIndex=obj.options.length;
return;
}
obj.show(obj.selectedIndex)
obj.hightLightValue=obj.options[obj.selectedIndex-1]
var downObj=document.getElementById("selecthtml")////////set scroll bar position
//alert(downObj.scrollTop);
//downObj.scrollTop=20;
var topDsts=downObj.scrollTop;/////distance from top to the "top" of list can be see
var viewBottomDsts=topDsts+obj.height;/////distance from top to the "bottom" the list can be see
if ((obj.selectedIndex)*19<viewBottomDsts)
{
return;
}
var scrollTopVal=((obj.selectedIndex)*19-obj.height)
if (scrollTopVal>0)
{
downObj.scrollTop=scrollTopVal;
}
return false;
//alert(obj.hightLightValue)
}
else if (event.keyCode==38)// user press "up" key
{
obj.selectedIndex--;
if(document.getElementById("selectcontent").style.visibility=="hidden")
{
obj.selectedIndex=1;
}
if(0==obj.selectedIndex)
{
obj.selectedIndex=1;
return;
}
obj.show(obj.selectedIndex)
obj.hightLightValue=obj.options[obj.selectedIndex-1]
//alert(obj.hightLightValue)
var downObj=document.getElementById("selecthtml")////////set scroll bar position
//alert(downObj.scrollTop);
//downObj.scrollTop=20;
var scrollTopVal=((obj.selectedIndex-1)*19);
var topDsts=downObj.scrollTop;/////distance from top to the "top" of the list can be see
var viewBottomDsts=topDsts+obj.height;/////distance from top to the "bottom" of the list can be see
if ((obj.selectedIndex-1)*19>topDsts)
{
return;
}
if (scrollTopVal<0)
{
scrollTopVal=0;
}
if (scrollTopVal>=0)
{
downObj.scrollTop=scrollTopVal;
}
}
else if(event.keyCode==13)// user press "enter" key
{
if(typeof(obj.hightLightValue)=="undefined")
{
return false;
}
if (obj.hightLightValue=="")
{
return false;
}
if(document.getElementById("selectcontent").style.visibility=="hidden")
{
return false;
}
obj.subInputBox.value=obj.hightLightValue.split("|&")[0];
setSelectValue(obj.hightLightValue.split("|&")[1],obj.name);
vDiv.style.visibility="hidden";
obj.subInputBox.select();
return false
}
else if(event.keyCode==35)/////////////////user press "End" button
{
obj.show(obj.options.length);
obj.hightLightValue=obj.options[obj.options.length-1];
var downObj=document.getElementById("selecthtml")////////set scroll bar position
var scrollTopVal=((obj.options.length+1)*19-obj.height)
if (scrollTopVal>0)
{
downObj.scrollTop=scrollTopVal;
}
}
else if (event.keyCode==36)/////////////////user press "Home" button
{
obj.show(1);
obj.hightLightValue=obj.options[0];
var downObj=document.getElementById("selecthtml")////////set scroll bar position
downObj.scrollTop=0;
}
else if (event.keyCode==34)//user press "page down" key
{
var pageSize=parseInt(obj.height/19,10);
var nextID=pageSize+obj.selectedIndex;
if (nextID>obj.options.length)
{
nextID=obj.options.length
}
obj.show(nextID);
obj.hightLightValue=obj.options[nextID-1];
var downObj=document.getElementById("selecthtml")////////set scroll bar position
var scrollTopVal=((nextID)*19-obj.height)
if (scrollTopVal>0)
{
downObj.scrollTop=scrollTopVal;
}
}
else if (event.keyCode==33)//user press "page up" key
{
var pageSize=parseInt(obj.height/19,10);
var nextID=obj.selectedIndex-pageSize;
if (nextID<1)
{
nextID=1;
}
obj.show(nextID);
obj.hightLightValue=obj.options[nextID-1];
var downObj=document.getElementById("selecthtml")////////set scroll bar position
var scrollTopVal=((nextID-1)*19)
if (scrollTopVal<0)
{
scrollTopVal=0;
}
if (scrollTopVal>=0)
{
downObj.scrollTop=scrollTopVal;
}
}
}
}
this.subInputBox.onkeydown=this.getKeydownFunction(this)
this.sbutton.onkeydown=this.getKeydownFunction(this)
this.sbutton.onclick=function(){combo.show(1)}
this.sendEventHandleToDropDown=function(obj,div)
{
return function()
{
if(event.propertyName=="style.visibility")
{
if (div.style.visibility=="hidden")
{
obj.selectedIndex=0;
}
//alert(obj.hightLightValue)
}
}
}
//document.getElementById("selectcontent").attachEvent("onpropertychange",this.sendEventHandleToDropDown(this,document.getElementById("selectcontent")))
this.getDownFocusFun=function(obj)
{
return function()
{
obj.subInputBox.focus();
}
}
this.show=function(showid)
{
this.selectedIndex=showid;
this.hightLightValue=this.options[showid-1];
document.getElementById("selecthtml").onfocus=this.getDownFocusFun(this);
if (this.enable==false)
{
return;
}
pDiv=eval(combo.divname)
pTable=eval(combo.tablename)
var isHiddenList=false;
if (vDiv.style.visibility=="hidden")
{
var vHTML='<table id=htmltable cellspacing="0" cellpadding="2" bgcolor="#EFF1F3" class="selecttable" width="100%">'
for (i=0;i<combo.options.length;i++)
{
if (showid-1==i)
{
vHTML+='<tr id="'+this.excusiveId+'_'+i+'" style="background-color:#000099;color:#ffffff;" fvalue="'+combo.options[i].split("|&")[1]+'" onclick="onClickItem(this,document.all.'+combo.name+',selectcontent,\''+this.name+'\');" ><td>'+combo.options[i].split("|&")[0]
}
else
{
vHTML+='<tr id="'+this.excusiveId+'_'+i+'" fvalue="'+combo.options[i].split("|&")[1]+'" onclick="onClickItem(this,document.all.'+combo.name+',selectcontent,\''+this.name+'\');" ><td>'+combo.options[i].split("|&")[0]
}
}
vHTML+="</table>"
vDivHtml.innerHTML=vHTML;
isHiddenList=true;
}
if(document.getElementById(this.excusiveId+'_'+this.previousSelectId)!=null)
{
document.getElementById(this.excusiveId+'_'+this.previousSelectId).style.backgroundColor="";
document.getElementById(this.excusiveId+'_'+this.previousSelectId).style.color="#000000";
if (showid>0)
{
document.getElementById(this.excusiveId+'_'+(showid-1)).style.backgroundColor="#000099";
document.getElementById(this.excusiveId+'_'+(showid-1)).style.color="#ffffff";
this.previousSelectId=showid-1;
}
//alert(document.getElementById(this.excusiveId+'_'+this.selectedIndex));
if (isHiddenList==false)
{
return;
}
}
this.getDownListMouseoverFun=function(obj,ii)
{
return function()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -