上一篇:妙用VBScript自制IE工具栏按钮(转) >>
js有几个缺陷。combox1.doSelectIdx(-1)我看不用调用了。
{
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.doSelectValue = doSelectValue;
this.focus = focus;
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 = "<INPUT type=@#text@# id=" + txtObjIdName + " name=" + txtObjIdName +
" onblur=@#" + objHandler + ".loseFocus()@# " +
" style=@#display: none; position: absolute@# 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<optLen; 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.txtObj.value=this.comObj.options[this.comObj.selectedIndex].text; //我加了这么一句
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 doSelectValue(v)
{
//alert(v)
var optLen = this.comObj.options.length;
for (i=0;i<optLen;i++)
{
if (this.comObj[i].value== v){
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();
}
}
下一篇:层不能跨框架(包括TEXTAREA)显示的解决办法 >>
相关文章:
- · IE里的探索(想定制自己的IE的可以看一看)
- · 这个object还有其他几种用法.现在贴了给大家.
- · 自动关闭窗口,方法总结
- · 这个脚本可以使你方便得获得各网站的连接速度
- · 列表框操作函数集合
- · 常用javascript函数(一)
- · 控制输出字符串的长度,可以区别中英文
- · 常用javascript函数(二)
- · 如何判断客户端浏览器的脚本js.vbs功能是否被禁止,通过隐藏域实现
- · 台湾的两篇文章,看看也好:唯讀的表單文字輸入項
- · Creating CSS Buttons (一)
- · Creating CSS Buttons (二)
- · 用javascript实现浮点数的截取小数位数,并四舍五入
- · three trim function(javascript)
- · 用ASP将javascript代码写入客户端执行的一种简易方法。。。
- · Trim Function in javascript
- · java分页源码
- · 过滤表格中的链接(用javascript提取表格中的数据)
- · 来看看哟.一个天气预报的小偷.可以偷到每天更新的全国24小时城市天气预报.
- · 一个把WORD转换成HTML的程序
- · 饮水思源,我从这里学到的知识投入应用,现在再奉献回给大家(可编辑页面的部分属性)
- · 用 WSH 想ASP 一样 查询数据库!(WSH 学习心得2)
- · 一段窗口自动关闭的源代码,不受js打开的限制,与大家共享!
- · 带进度条的关闭窗口,绝对有用!并可根据需要改写。
- · 一组javascript绘图函数
- · 限制只能中文输入的方法。(详细讲解,对象初学者)
- · 一般的页面滚动条是在右边的,想让他在左边吗:)
- · 确认是否关闭浏览器或转到其它页面(javascript)(做聊天室或在线人数的时候可以用上)
- · <body onkeypress=alert(event.keyCode)>请按任意键,你将得到该键的键值!(转)
- · 利用cookie收藏网站
- · 转贴一个扫雷游戏脚本
- · 动态按钮生成器(上)
- · 用Cookie实现仅弹出一次窗口(javascript)(转)
- · 动态按钮生成器(下)
- · 一全很经典的堆积演示程序(javascript)(转)
- · 一个很酷的程序javascript做的MID歌曲搜索播放器[IE](JS)_(转)
- · 一个查看ASP的javascript程序,方便大家学习ASP程序(JS)_转
- · 长串连续英文字符自动回行的方法(转)
