请教高手,则么使做出的下拉菜单既可以给人选择,又可以在里面输入,在线等待

请教高手,则么使做出的下拉菜单既可以给人选择,又可以在里面输入
---------------------------------------------------------------

收藏了一个,也是别人提供的。看看http://webfx.eae.net/dhtml/combobox/combo_demo.htm
---------------------------------------------------------------

function getLeftPostion( theObj )
{
var pos = 0;
while ( theObj != null )
{
pos += theObj.offsetLeft;
//get the Object which contain theObj.
theObj = theObj.offsetParent;
}
return pos;
}
function getTopPostion( theObj )
{
var pos = 0;
while ( theObj != null )
{
pos += theObj.offsetTop;
//get the Object which contain theObj.
theObj = theObj.offsetParent;
}
return pos;
}
function checkVersion()
{
var isBadVersion=true;
var curVer=navigator.appVersion;
var pos=parseInt(curVer.indexOf("MSIE"));
if (pos>=1)
{
var intVer=parseInt(curVer.charAt(pos+5));
if (intVer>=5)
{ isBadVersion=false;}
}
if (isBadVersion)
{
var msg="This page may not be displayed properly:\n"+
" This product requires Microsoft Internet Explorer 5 or later browser only.";
alert(msg);
}
}

//check the browser version
checkVersion();

// the array of comboBoies
theArray = new Array();

function combobox(objId, objHandler)
{
this.comObj = document.all[objId];
this.comObj.selectedIndex = -1;
this.getValue = getValue;
this.doResize = doResize;
this.doChange = doChange;
this.loseFocus = loseFocus;
this.doSelectIdx = doSelectIdx;
this.focus = focus;
this.keyPress = keyPress;
this.change = change;

var strMsg="";

//------------------------------------------------------------------------------------------------------
// create the text object
//------------------------------------------------------------------------------------------------------
var txtObjIdName = objId + "_text";

if (document.all[txtObjIdName] != null)
{
strMsg="The following id: '" + txtObjIdName +"' is used internally by the Combo Box!\r\n"+
"Use of this id in your page may cause malfunction. Please use another id for your controls.";
alert(strMsg);
}

var txtInner = "

1<input "="" +="" id=" + txtObjIdName + " name=" + txtObjIdName + " onblur='" + objHandler + ".loseFocus()' onchange='" + objHandler + ".keyPress()' onkeyup='" + objHandler + ".keyPress()' style="display: none; position: absolute" type="text" value=""/>

";

this.comObj.insertAdjacentHTML("afterEnd", txtInner);

this.txtObj = document.all[txtObjIdName];

//------------------------------------------------------------------------------------------------------
// end
//------------------------------------------------------------------------------------------------------

this.beResizing = false;
this.doResize();
theArray[theArray.length] = this;
}

function loseFocus()
{
var theComObj = this.comObj;
var theTxtObj = this.txtObj;
var i;
theComObj.selectedIndex = -1;

if (theTxtObj.value == "")
{
return;
}

var optLen = theComObj.options.length;
for (i=0; i

 1<optlen; "="" "+="" "+(this.txtobj.style.poswidth="" (!this.beresizing)="" ((i="" (comval="txtVal)" )+")";="" +="" +(this.comobj.offsetwidth)+"="" -="" 16;="" 1;="" 2="" ;="" comval="theComObj.options[i].text;" dochange()="" doresize()="" doselectidx(i)="" function="" getvalue()="" i++)="" idx="this.comObj.selectedIndex;" if="" opt="this.comObj.options[idx];" optlen="this.comObj.options.length;" return="" return;="" strrect="rect(0 " thecomobj.selectedindex="i;" this.beresizing="false;" this.comobj.offsetheight="" this.comobj.selectedindex="-1;" this.comobj.style.clip="strRect;" this.comobj.style.position="absolute" this.comobj.style.posleft="this.txtObj.style.posLeft;" this.comobj.style.postop="this.txtObj.style.posTop;" this.offwidth="this.comObj.offsetWidth;" this.txtobj.focus();="" this.txtobj.select();="" this.txtobj.style.display="" this.txtobj.style.posheight="this.comObj.offsetHeight;" this.txtobj.style.posleft="getLeftPostion(this.comObj);" this.txtobj.style.postop="getTopPostion(this.comObj)" this.txtobj.style.poswidth="this.comObj.offsetWidth" this.txtobj.value="opt.text;" this.txtobj.value;="" txtval="theTxtObj.value;" var="" {="" }="">=0) &amp;&amp; (i &lt; optLen))   
 2{   
 3this.comObj.selectedIndex = i;   
 4this.txtObj.value = this.comObj.options[i].text;   
 5return;   
 6}   
 7this.txtObj.value = "";   
 8}   
 9  
10  
11function focus()   
12{   
13this.txtObj.focus();   
14}   
15  
16/*resize all combobox when window be resized*/   
17function resetAllSize()   
18{   
19var i;   
20for (i=0; i &lt; theArray.length; i++)   
21{   
22theArray[i].doResize();   
23}   
24}   
25////////////////定位函数开始,我加的///////////////   
26function keyPress()   
27{   
28var txtStr;   
29var comStr;   
30var maxInt = 0;   
31var defInt = 0;   
32var defJ;   
33txtStr = this.txtObj.value;   
34//document.form1.test.value=txtStr;   
35var j;   
36for(j=0;j<this.comobj.options.length;j++) !="comStr.charCodeAt(m))" &brvbardx="" (defint="" *="" 2002-06-13="" <="" \---------------------------------------------------------------="" and="" array();="" array.prototype.remove="function(dx)" arvidsson="" break;="" build="" by="" combo_demo.htm="" combobox="" comstr="this.comObj.options[j].text;" contact.html#erik="" defint="maxInt;" defj="j;" dhtml="" erik="" fixed="" for(m="0;m&lt;txtStr.length+1;m++)" global_combo_array="new" global_run_event_hook="true;" http:="" if="" if(isnan(dx)="" if(txtstr.charcodeat(m)="" improved="" jared="" m;="" maxint="m;" maxint)="" mozilla="" nuzzolillo="" performance="" support="" this.comobj.selectedindex="defJ;" updated="" var="" webfx.eae.net="" {="" }="" ¦="" 里面包含一个combobox.js,内容是,把它保存在和你combo_demo.htm相同目录即可="">this.length){self.status='Array_remove:invalid request-'+dx;return false}   
37for(var i=0,n=0;i&lt;this.length;i++)   
38{   
39if(this[i]!=this[dx])   
40{   
41this[n++]=this[i]   
42}   
43}   
44this.length-=1   
45}   
46  
47function ComboBox_make()   
48{   
49var bt,nm;   
50nm = this.name+"txt";   
51  
52this.txtview = document.createElement("INPUT")   
53this.txtview.type = "text";   
54this.txtview.name = nm;   
55this.txtview.id = nm;   
56this.txtview.className = "combo-input"   
57this.view.appendChild(this.txtview);   
58  
59this.valcon = document.createElement("INPUT");   
60this.valcon.type = "hidden";   
61this.view.appendChild(this.valcon)   
62  
63var tmp = document.createElement("IMG");   
64tmp.src = "___";   
65tmp.style.width = "1px";   
66tmp.style.height = "0";   
67this.view.appendChild(tmp);   
68  
69var tmp = document.createElement("BUTTON");   
70tmp.appendChild(document.createTextNode(6));   
71tmp.className = "combo-button";   
72  
73this.view.appendChild(tmp);   
74tmp.onfocus = function () { this.blur(); };   
75tmp.onclick = new Function ("", this.name + ".toggle()");   
76}   
77  
78function ComboBox_choose(realval,txtval)   
79{   
80this.value = realval;   
81var samstring = this.name+".view.childNodes[0].value='"+txtval+"'"   
82window.setTimeout(samstring,1)   
83this.valcon.value = realval;   
84}   
85  
86function ComboBox_mouseDown(e)   
87{   
88var obj,len,el,i;   
89el = e.target ? e.target : e.srcElement;   
90while (el.nodeType != 1) el = el.parent</this.comobj.options.length;j++)></optlen;>
Published At
Categories with Web编程
comments powered by Disqus