时间: 2021-07-31 作者:daque
<script src="editableselect.js"></script><select id="editableselect"><option>不妨编纂的select第二版</option><option>bencalie创造</option></select>
=======================editableselect.js
window.onload=function(){ var objselect=editableselect var obj=document.all.editableselect gettop=obj.offsettop; getleft=obj.offsetleft; while(objselect=objselect.offsetparent){ gettop+=objselect.offsettop; getleft+=objselect.offsetleft; }
var onewitem=document.createelement("object"); document.body.insertbefore(onewitem); onewitem.outerhtml="<object id=editable style=\"z-index:2;position:absolute\" type=\"text/x-scriptlet\" data=\"addin2.htm\"></object>";
editable.style.left=getleft+1 editable.style.top=gettop+1 editable.style.width=obj.offsetwidth-19 editable.style.height=obj.offsetheight-3 obj.onchange=function(){editable.str(obj.options[obj.selectedindex].text)} obj.onresize=function(){editable.style.width=obj.offsetwidth-19}}
function addnewoption(value){ editableselect.options[editableselect.length]=new option(value,value) }
=======================addin2.htm
<script language="vbs">function public_str(thestrin) strin.value=thestrinend function</script><body leftmargin=0 topmargin=0><script language="javascript">function check(){var obj=parent.document.all.editableselectvar thevalue=document.all.strin.value.replace(/^\s*/g,"").replace(/\s*$/g,"")if(event.keycode==13){if(thevalue!=""){for(i=0;i<obj.length;i++) if(obj.options[i].text==thevalue){ alert("该选项仍旧生存!"); document.all.strin.focus(); document.all.strin.value=""; return; }parent.addnewoption(thevalue) }document.all.strin.value=""}}</script><input id=strin style='border:0;width:100%;height:100%;padding-top:2px' onkeydown=check()></body>