可編輯下拉框-HTML 複製程式碼 程式碼如下: A類 B類 C類 D類別 可編輯下拉框-JS 複製程式碼 程式碼如下: 可編輯下拉框 可編輯下拉框 作者 <BR>function combox(obj, select){ <BR>this.obj=obj <BR>this.name=select; <BR>this.select=document.getElementsByName(select)[0]; <BR>/*要轉換的下拉框*/ <BR>} <BR>/*初始化物件*/ <BR>combox.prototype.init=function(){ <BR>var inputbox="<input name='combox_" this.name "' onchange='" this. obj ".find()' " <BR>inputbox ="style='position:absolute;width:" (this.select.offsetWidth-16) ";height:" this.select.offsetHeight ";left:" getL( this.select) ";top:" getT(this.select) "'>" <BR>document.write(inputbox) <BR>with(this.select.style){ <BR>left=getL(this.select ) <BR>top=getT(this.select) <BR>position="absolute" <BR>clip="rect(0 " (this.select.offsetWidth) " " this.select.offsetHeight " " (this.select .offsetWidth-18) ")" <BR>/*切割下拉框*/ <BR>} <BR>this.select.onchange=new Function(this.obj ".change()") <BR>this.change () <br><br>} <BR>/*初始化結束*/ <br><br>////////物件事件定義/////// <BR>combox.prototype.find =function(){ <BR>/*當搜尋到輸入框的值時,下拉框自動定位*/ <BR>var inputbox=document.getElementsByName("combox_" this.name)[0] <BR>with( this.select){ <BR>for(i=0;i<options.length;i ) <BR>if(options[i].text.indexOf(inputbox.value)==0){ <BR>selectedIndex= i <BR>this.change(); <BR>break; <BR>} <BR>} <BR>} <br><br>combox.prototype.change=function(){ <BR>/*定義下拉框的onchange事件*/ <BR>var inputbox=document.getElementsByName("combox_" this.name)[0] <BR>inputbox.value=this.select.options[this.select.selectedIndex].text;🎜 >with(inputbox){select();focus()}; <BR>} <BR>////////物件事件結束/////// <BR>/*公用定位函數(獲取控制項絕對座標)*/ <BR>function getL(e){ <BR>var l=e.offsetLeft; <BR>while(e=e.offsetParent)l =e.offsetLeft; <BR>return l <BR> } <BR>function getT(e){ <BR>var t=e.offsetTop; <BR>while(e=e.offsetParent)t =e.offsetTop; <BR>return t <BR>} <BR>/ *結束*/ <BR> <BR>var a=new combox("a","fason") <BR>a.init() <BR>