具有edit功能的combobox

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 flyycyu 的 blog

这是一个自己编写的htc控件

<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>

本文关键:combobox edit
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top