我的一亩三分地 我就喜欢!
13fen  设为主页
 收藏本站
 
当前位置: > 一亩三分地:首页 > 网络学院 > 网络编程 > ASP专区 > Asp客户端/系统 > js有几个缺陷。combox1.doSelectIdx(-1)我看不用调用了。
热门文章排行
热门文章排行 手推车”功能的实现(10-07)
八大法则防范ASP网站漏洞(10-23)
ASP教程十一、调试ASP脚本(10-23)
在JSP中访问数据库大全(10-23)
虚机服务中常见Asp.Net低级错误一览(03-21)
精采文章排行
精采文章排行 ASP.NET实现抓取网页中的链接(11-15)
ASP连接数据库的11种方法(11-10)
如何动态创建网页的RSS内容摘要(11-10)
ASP网站漏洞及入侵防范方法(11-10)
ASP自定义函数:对字符串正则替换(11-10)
技术专题推荐
网管论坛交流
 

js有几个缺陷。combox1.doSelectIdx(-1)我看不用调用了。 

作者:佚名   来源:一亩三分地   点击:   日期:2007-03-22

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.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();
  }
}


 

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【论坛讨论

   相关文章:
·ASP中巧用Response属性 ·第六课:ASP脚本循环语句
·在 Web 页上使用条件数值格式 ·连接数据库查询手册(不仅仅适用于asp)
·警惕"给你的FileSystemObject对象加把锁" ·用ASP做全文检索

   文章评论:(条)
  
 请留名: 匿名评论   点击查看所有评论 网管论坛
 

  责任编辑:一分  声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。