欢迎光临
我们一直在努力

具有edit功能的select-ASP教程,ASP技巧

建站超值云服务器,限时71元/月

1、

<html>

<head>

<public>

<component tagname="combobox">

<property name="text" get="get_text" put="put_text">

<property name="width" get="get_width" put="put_width">

<method name="setfocus" internalname="htcfocus">

<method name="additems" internalname="htcadditems">

<event name="onyycenter" id="identer">

<event name="onyycchoose" id="idchoose">

<attach event="oncontentready" onevent="htcinit()">

</component>

</public>

<script language="javascript">

function htcinit()

{

defaults.viewlink=document;

defaults.viewinheritstyle=false;

body_init();

}

function htcadditems(items)

{

var i,len;

len=pcombo.options.length;

for(i=0;i<len;i++)

{pcombo.remove(0);}

for(i=0;i<items.length;i++)

{

var o;

if((typeof items[i])==string)

{

if(!hasthevalue(items,i))

{

o=document.createelement(option);

o.text=items[i];

pcombo.add(o);

}

}

}

}

function htcfocus()

{

ptext.focus();

}

function get_text()

{

return ptext.value;

}

function put_text(value)

{

ptext.value=value;

}

function get_width()

{

return pcombo.style.width;

}

function put_width(value)

{

pcombo.style.width=value;

}

</script>

<script language="javascript">

function body_init()

{

var iright=pcombo.clientwidth;

var ibottom=pcombo.clientheight;

var ileft=(pcombo.clientwidth-18);

pcombo.style.clip=rect(0,+iright+,+ibottom+,+ileft+);

ptext.style.width=(pcombo.clientwidth);

ptext.style.height=(pcombo.clientheight);

ptext.style.top=0;

ptext.style.left=0;

}

function combo_select()

{

ptext.value=pcombo.options[pcombo.selectedindex].text;

}

function text_chkkey()

{

if(event.keycode==13)

{

identer.fire();

}

}

function hasthevalue(sitems,i)

{

var ii;

for(ii=0;ii<i;ii++)

{

if(sitems[ii]==sitems[i])

return true;

}

return false;

}

</script>

</head>

<body>

<select style="position:absolute;left:0;top:0;" onchange="combo_select()" name="pcombo">

</select>

<input style="position:absolute;left:0;top:0;z-index:4000" onkeypress="text_chkkey()" type="text" name="ptext">

</body>

</html>

2、

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 = "<input type=text id=" + txtobjidname + " name=" + txtobjidname + " onblur=" + objhandler + ".losefocus() " + " onkeyup=" + objhandler + ".keypress()" + " onchange=" + objhandler + ".keypress()" + " 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.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<this.comobj.options.length;j++)

{

comstr = this.comobj.options[j].text;

var m;

for(m=0;m<txtstr.length+1;m++)

{

if(txtstr.charcodeat(m) != comstr.charcodeat(m))

{

maxint = m;

break;

}

}

if (defint < maxint)

{

defint = maxint;

defj = j;

}

}

this.comobj.selectedindex = defj;

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 具有edit功能的select-ASP教程,ASP技巧
分享到: 更多 (0)