<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head><body> <select id="select">
</select> <input type="text" id="shuiguo" onblur="choose()" /> <script language="javascript"> function choose(){ var sg = ['黑梅','龙眼','黑枣','芒果','苹果','苹果1','龙荔','荔枝']; var name = document.getElementById('shuiguo').value; var faceName = eval("/" + name + "/"); var select = document.getElementById('select'); if(name != ''){
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<select id="select">
</select>
<input type="text" id="shuiguo" onblur="choose()" />
<script language="javascript">
function choose(){
var sg = ['黑梅','龙眼','黑枣','芒果','苹果','苹果1','龙荔','荔枝'];
var name = document.getElementById('shuiguo').value;
var faceName = eval("/" + name + "/"); var select = document.getElementById('select');
if(name != ''){
for(var i=0;i<sg.length;i++){
if(faceName.test(sg[i])){
select.add(new Option(sg[i],i));
}
}
}else{
for(var i=0;i<sg.length;i++){
select.add(new Option(sg[i],i));
}
}
}
</script></body>
</html>给你做个参考