-
您的位置:首页 → 网页设计 → ASP实例 → 下拉菜单输入根据输入内容自动定位
下拉菜单输入根据输入内容自动定位
时间:2004/11/7 3:01:00来源:本站整理作者:蓝点我要评论(0)
-
下拉菜单支持输入,并根据输入内容自动定位:
参考:演员发表于 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:\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 = "";
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
{
var comVal = theComObj.options[i].text;
var txtVal = theTxtObj.value;
if (comVal == txtVal)
{
theComObj.selectedIndex = i;
return;
}
}
}
function doResize()
{
if (!this.beResizing)
{
this.beResizing = true;
this.txtObj.style.display="none";
this.comObj.style.position="static";
this.txtObj.style.posLeft = getLeftPostion(this.comObj);
this.txtObj.style.posTop = getTopPostion(this.comObj) + 1;
this.txtObj.style.posWidth = this.comObj.offsetWidth - 16;
this.txtObj.style.posHeight = this.comObj.offsetHeight;
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;
var strRect = "rect(0 "+(this.comObj.offsetWidth)+" "+ this.comObj.offsetHeight + " "+(this.txtObj.style.posWidth - 2 )+")";
this.comObj.style.clip = strRect;
this.txtObj.style.display="";
this.beResizing = false;
}
}
function doChange()
{
var idx = this.comObj.selectedIndex;
var opt = this.comObj.options[idx];
this.txtObj.value = opt.text;
this.txtObj.focus();
this.txtObj.select();
this.comObj.selectedIndex=-1;
}
function getValue()
{
return this.txtObj.value;
}
function doSelectIdx(i)
{
var optLen = this.comObj.options.length;
if ((i >=0) && (i < optLen))
{
this.comObj.selectedIndex = i;
this.txtObj.value = this.comObj.options[i].text;
return;
}
this.txtObj.value = "";
}
function focus()
{
this.txtObj.focus();
}
/*resize all combobox when window be resized*/
function resetAllSize()
{
var i;
for (i=0; i < theArray.length; i++)
{
theArray[i].doResize();
}
}
////////////////定位函数开始,我加的///////////////
function keyPress()
{
var txtStr;
var comStr;
var maxInt = 0;
var defInt = 0;
var defJ;
txtStr = this.txtObj.value;
//document.form1.test.value=txtStr;
var j;
for(j=0;j
{
comStr = this.comObj.options[j].text;
var m;
for(m=0;m
{
if(txtStr.charCodeAt(m) != comStr.charCodeAt(m))
{
maxInt = m;
break;
}
}
if (defInt < maxInt)
{
defInt = maxInt;
defJ = j;
}
}
this.comObj.selectedIndex = defJ;
}
相关阅读
Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么
-
热门文章
没有查询到任何记录。
最新文章
迅雷新手完全入门手册
asp下面javascript上传图片限制格式大小方法告诉大家网页弹出窗口应用总结ASP常见错误类型大全asp常见错误分析和解决办法
人气排行
总是弹出visual studio 实时调试器 三种解决SQLSERVER存储过程及调用详解Asp获取真实IP地址ASP中连接Mssql的几种方法一个简单好用的UBB编辑器(含代码)如何用Split将字符串转换为数组并获取数组下ASP防止表单重复提交的办法告诉你免费的简单聊天室源代码
查看所有0条评论>>