关于用汉语拼音首字母检索的问题
想做一个对下拉框用汉语拼音首字母检索的题目.
但苦于下拉框没法输入,好像onkeypress属性可以取到输入的值,但又不知道怎么取.
我把代码改成简单的HTML文件了,大家帮忙看看,
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<script language= 'javascript '>
var onecount;
onecount=0;
array_b=new Array();
array_b[0]=new Array( "nbsaqscjdglj ", "宁波市安全生产监督管理局 ");
array_b[1]=new Array( "cxsghj ", "慈溪市规划局 ");
array_b[2]=new Array( "jdqzfww ", "江东区政府外网 ");
array_b[3]=new Array( "nbygezyyxgs ", "宁波雅戈尔置业有限公司 ");
onecount=4;
//数据检索
function search(){
var txt = document.getElementById( "text1 ").value;
//alert(txt); return;
//var array_b_length = array_b.length;
var txt_length = txt.length;
var temp = new Array();
for(var i=0;i <onecount;i++){
if(txt_length <=array_b[i][0].length){
if(array_b[i][0].substring(0,txt_length)==txt){
temp.push(i);
//alert(i+ "@ "+txt_length+ "@ "+array_b[i][0]+ "@ "+array_b[i][0].substring(0,txt_length)+ "@ "+txt);
}
}
}
var totaldata = new Array();
var temp_length = temp.length;
for(var j=0;j <temp_length;j++){
totaldata.push(array_b[temp.pop(j)]);
//alert(temp.pop(j));
}
createObj(totaldata);
}
//创建对象
createObj = function(totaldata){
var selectObj = document.getElementById( "select1 ");
//var selectObj_length = selectObj.options.length;
var selectObj_length = selectObj.children.length;
while(--selectObj_length> =0){
selectObj.children[selectObj_length].removeNode(true);
}
var module = null;
var totaldata_length = totaldata.length;
for(i=totaldata_length-1;i> =0;i--){
module = document.createElement( "option ");
module.value=totaldata[i][0];
module.innerText=totaldata[i][1];
selectObj.appendChild(module);
}
//end
}
</script>
</head>
<body>
<center>
<br> <br> <br> <br>
<select id= "select1 " style= "width:200 ">
<option value= "nbsaqscjdglj ">
宁波市安全生产监督管理局
</option>
<option value= "cxsghj ">
慈溪市规划局
</option>
<option value= "jdqzfww ">
江东区政府外网
</option>