日期:2014-05-16 浏览次数:20353 次
<html>
<head>
<script>
window.onload = function(){
var oInput = document.getElementById("input_default");
oInput.focus();
}
</script>
</head>
<body onload="Init()">
<form name=frm method="post" action="2.asp">
<table>
<tr>
<td><input name="info" style="width:300px" onkeyup="SelectTip(0)" id="input_default" ></td>
</tr>
<tr>
<td>
<span id="check"><select name="check" style="width:300px" size=10 onchange="info.value=options[selectedIndex].text;">
<option value='105'>105</option>
<option value='104'>104</option>
<option value='103'>103</option>
<option value='102'>102</option>
<option value='101'>101</option>
<option value='205'>205</option>
<option value='204'>204</option>
<option value='203'>203</option>
<option value='202'>202</option>
<option value='201'>201</option>
</select></span>
</td>
</tr>
<tr><td><input class="button" type="submit" name="Submit" value="新增"></td></tr>
</table>
</form>
<script language="javascript">
var TempArr=[];//存贮option
function Init(){
var SelectObj=document.frm.elements["check"]
/*将数据存入数组*/
with(SelectObj)
for(i=0;i<length;i++)TempArr[i]=[options[i].text,options[i].value]
}
function SelectTip(flag){
var txtObj=document.frm.elements["info"]
var SelectObj=document.getElementById("check")
var Arr=[]
with(SelectObj){
var SelectHTML=innerHTML.match(/<[^>]*>/)[0]
for(i=0;i<TempArr.length;i++)
if(TempArr[i][0].indexOf(txtObj.value)==0||flag)//若找到以txt的内容开头的,添option。若flag为true,对下拉框初始化
Arr[Arr.length]="<option value='"+TempArr[i][1]+"'>"+TempArr[i][0]+"</option>"
innerHTML=SelectHTML+Arr.join()+"</SELECT>"
}
}
</script>
</body>
</body>
</html>