日期:2014-05-16 浏览次数:20377 次
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>Test</title> </head> <body> <input type="text" value="" id="txtTest" onkeyup="Test();"> <select id="selectTest"> <option value="0">选择项</option> <option value="1">abc</option> <option value="2">def</option> </select> <script type="text/javascript"> function Test(){ var obj=document.getElementById("txtTest").getAttribute("value"); var select=document.getElementById("selectTest"); var temp=0; for(var i=0;i<select.options.length;i++){ if(select.options[i].innerText==obj){ temp=i; break; } } select.options[temp].selected=true; } </script> </body> </html>
------解决方案--------------------
var a=["2","22","2222","222222","222222","2222"];
function finds(){
var see=document.getElementById("se");
var tee=document.getElementById("te");
see.length=0;
var value1=tee.value;
for(var i=0;i<a.length;i++){
if(a[i].indexOf(value1)==0){
var o=new Option(a[i],a[i]);
see[see.length]=o;
}
}
see.size=see.length;
}
通过设置下拉框的size属性