下拉菜单输入,根据输入内容自动定位
程序员文章站
2022-06-19 19:24:26
下拉菜单支持输入,并根据输入内容自动定位:参考:演员发表于 10/23/2001 8:58:16 am 的文章 “罗亭的可输入下拉框的解密简化版.”,在此特别感谢相关人等。本文为这个下拉框增加了一点...
下拉菜单支持输入,并根据输入内容自动定位:
参考:演员发表于 10/23/2001 8:58:16 am 的文章 “罗亭的可输入下拉框的解密简化版.”,在此特别感谢相关人等。
本文为这个下拉框增加了一点小小的功能:输入能够定位在已有的选择框内。还有一个缺点,各位给改改:输入的时候不能够自动拉开选择框,怎么办?
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: "+
" 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! "+
"use of this id in your page may cause malfunction. please use another id for your controls.";
alert(strmsg);
}
var txtinner = "<input type=text id=" + txtobjidname + " name=" + txtobjidname + " onblur=" + objhandler + ".losefocus() " + " onkeyup=" + objhandler + ".keypress()" + " onchange=" + objhandler + ".keypress()" + " style=display: none; position: absolute value= >";
参考:演员发表于 10/23/2001 8:58:16 am 的文章 “罗亭的可输入下拉框的解密简化版.”,在此特别感谢相关人等。
本文为这个下拉框增加了一点小小的功能:输入能够定位在已有的选择框内。还有一个缺点,各位给改改:输入的时候不能够自动拉开选择框,怎么办?
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: "+
" 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! "+
"use of this id in your page may cause malfunction. please use another id for your controls.";
alert(strmsg);
}
var txtinner = "<input type=text id=" + txtobjidname + " name=" + txtobjidname + " onblur=" + objhandler + ".losefocus() " + " onkeyup=" + objhandler + ".keypress()" + " onchange=" + objhandler + ".keypress()" + " style=display: none; position: absolute value= >";
上一篇: 《Java编程入门》笔记——阿里云大学
下一篇: 怎么吃燕窝效果最好?