日期:2014-05-16 浏览次数:20346 次
<html> <head> <script type="text/javascript"> function selectOne(myselectid,keywords)//参数myselectid是select的id,参数keywords输入的keyword { keywords = keywords.replace(/ /g,""); //去掉空格 var myselect = document.getElementById(myselectid); //得到select对象 for(i=0;i<myselect.length;i++)// 循环option { if(myselect.options[i].text.indexOf(keywords)!=-1) //判断option的text是否包含keyword { myselect.options[i].selected=true;//选中 break; } else { myselect.options[i].selected=false; //不包含keywords的取消选中 } } } </script> </head> <body> <input id="input_text" type="text" onkeyup="selectOne('select_by_input',document.getElementById('input_text').value)"></input> <select id="select_by_input"> <option>请选择......</option> <option>文本框与下拉列表的组合</option> <option>不包含keywords的取消选中</option> <option>Java编程思想第四版</option> <option>判断option的text是否包含keyword</option> <option>参数myselectid是select的id</option> <option>得到select对象</option> <option>去掉空格</option> <option>循环option</option> </select> </body> </html>