Editable listbox
/* Common elements */
body{font:small/1.2em arial,helvetica,clean,sans-serif;font:x-small;}
table{font-size:inherit;font:x-small;}
/* Options Templates */
.ac_menu{border:1px solid #3162A6;background-color:#F6F6F6;cursor:default;overflow:hidden;-moz-box-sizing:border-box;
height:expression((this.scrollHeight>210)?"210px":"auto")}
.ac_menuitem{width:100%;color:#141414;padding:2px;cursor:pointer;cursor:hand;}
.ac_menuitem_selected{background-color:#D6DEEC;width:100%;color:#141414;padding:2px;cursor:pointer;cursor:hand;}
/* JK */
.minHeightTextarea{
height:expression((this.scrollHeight>150)?"150px":(this.scrollHeight+5)+"px");
overflow : auto;
}
var AC_TAB = 9; // make the selection
var AC_ENTER = 13; // make the selection
var AC_UP_ARROW = 38; // move the drop down list selection up by one
var AC_DOWN_ARROW = 40; // move the drop down list selection down by one
var theListDiv;
var theComboxObj;
οnlοad=OnLoad
function OnLoad()
{
setTimeout("Initialize()", 100);
}
function Initialize()
{
AddListDivFun(document.all.tofield);
AddListDivFun(document.all.ccfield);
}
function AddListDivFun(obj)
{
var theListArray=eval(obj.id+"ListArray");
var tempStr='
'
+'
";
obj.insertAdjacentHTML("afterEnd",tempStr);
theListDiv=eval(obj.id+"ListDiv");
obj.οnfοcus=AC_OnFocus;
obj.οnblur=AC_OnBlur;
obj.onpropertychange=AC_OnPropertyChange;
obj.οnkeydοwn=AC_OnKeyDown;
obj.autoComplete="off";
}
function AC_OnFocus(obj)
{
if(obj==null) obj=event.srcElement;
theListDiv=eval(obj.id+"ListDiv");
theComboxObj=obj;
theListDiv.style.visibility="visible";
adjustListDivScroll();
}
function AC_OnBlur(obj)
{
if(obj==null) obj=event.srcElement;
if(theListDiv.contains(document.activeElement)) obj.focus();
else theListDiv.style.visibility="hidden";
}
function AC_OnPropertyChange(obj)
{
if(theListDiv==null) return ;
if(obj==null) obj=event.srcElement;
theListDiv.selectedIndex=-1;
var theFirstVisibleIndex=-1;
var objValue=obj.value;
for(var i=0;i
{
if(theListDiv.children[i].textValue.indexOf(objValue)==0)
{
if(theFirstVisibleIndex==-1) theFirstVisibleIndex=i;
theListDiv.children[i].className="ac_menuitem";
theListDiv.children[i].style.display="";
theListDiv.children[i].innerHTML=""+htmlEncode(objValue)+""+htmlEncode(theListDiv.children[i].textValue.substr(objValue.length));
}
else
theListDiv.children[i].style.display="none";
if(theListDiv.selectedIndex==-1 && theListDiv.children[i].textValue==objValue) theListDiv.selectedIndex=i;
}
if(theListDiv.selectedIndex==-1 && theFirstVisibleIndex!=-1)
{
theListDiv.selectedIndex=theFirstVisibleIndex;
}
if(theListDiv.selectedIndex!=-1) theListDiv.children[theListDiv.selectedIndex].className="ac_menuitem_selected";
adjustListDivScroll();
}
function AC_OnKeyDown(obj)
{
if(theListDiv==null) return ;
if(obj==null) obj=event.srcElement;
var keyCode=event.keyCode;
if(keyCode==AC_ENTER) keyCode=event.keyCode=AC_TAB;
if(keyCode==AC_TAB && theListDiv.selectedIndex!=-1)
{
obj.value=theListDiv.children[theListDiv.selectedIndex].textValue;
return ;
}
if(keyCode==AC_UP_ARROW && theListDiv.selectedIndex!=-1)
{
for(var i=theListDiv.selectedIndex-1;i>-1;i--)
{
if(theListDiv.children[i].style.display!="none")
{
theListDiv.children[theListDiv.selectedIndex].className="ac_menuitem";
theListDiv.selectedIndex=i;
theListDiv.children[theListDiv.selectedIndex].className="ac_menuitem_selected";
adjustListDivScroll();
break;
}
}
}
if(keyCode==AC_DOWN_ARROW && theListDiv.selectedIndex!=-1)
{
for(var i=theListDiv.selectedIndex*1+1;i {
if(theListDiv.children[i].style.display!="none")
{
theListDiv.children[theListDiv.selectedIndex].className="ac_menuitem";
theListDiv.selectedIndex=i;
theListDiv.children[theListDiv.selectedIndex].className="ac_menuitem_selected";
adjustListDivScroll();
break;
}
}
return;
}
}
function htmlEncode(str)
{
if(str==null) return "";
str=str.replace(/ str=str.replace(/>/ig,">");
str=str.replace(/"/ig,""");
return str;
}
function mouseOverListDivFun(event)
{
if(event.toElement!=theListDiv) event.toElement.style.backgroundColor="#E6E6E6";
}
function mouseOutListDivFun(event)
{
if(event.fromElement!=theListDiv) event.fromElement.style.backgroundColor="";
}
function mouseDownListDivFun(event)
{
var selectedStr="";
if(event.srcElement==theListDiv) return;
else if(event.srcElement.tagName=="B") selectedStr=event.srcElement.parentElement.textValue ;
else selectedStr=event.srcElement.textValue;
theComboxObj.value=selectedStr;
theComboxObj.blur();
}
function adjustListDivScroll()
{
if ( theListDiv==null || theListDiv.selectedIndex==-1 ) return ;
var i=theListDiv.selectedIndex;
if((theListDiv.children[i].offsetToptheListDiv.scrollTop+200))
theListDiv.scrollTop=theListDiv.children[i].offsetTop-95;
}
----------------------------
对于从数据库调下拉列表内容的方法,只需替换
var tofieldListArray=[<%
UserAuthInte uAInte = new UserAuthInte();
List funcList = uAInte.getAllFuncModels();
Iterator ite = funcList.iterator();
while (ite.hasNext() ) {
FuncModel funcM = (FuncModel) ite.next();
out.println("/""+funcM.getFunctionName()+"/",");
}%>];
var ccfieldListArray=tofieldListArray;
对于接受该下拉列表值,可用
String tofield = new String(request.getParameter("To").getBytes("ISO8859_1"),"GBK");
用name而不是ID。