当前位置: 代码迷 >> JavaScript >> 怎么根据文本框动态列出下拉列表
  详细解决方案

怎么根据文本框动态列出下拉列表

热度:340   发布时间:2012-02-13 17:20:26.0
如何根据文本框动态列出下拉列表
像网易邮箱一样在发送栏里面输入“w”,就会动态列出w开头的所有用户名,望大侠指点一下。

------解决方案--------------------
JS版里艘dh20156这个ID
然后内容是艘%
有个。。dhcombobox貌似就是的样子。。
------解决方案--------------------
抛砖引玉....
<style>
#Text1 {
z-index:19;width:200px;
}
#s2 {
z-index:19;width:200px;
}
#s1 {
position:relative;top:0px;
width:19px; text-align:right; overflow:hidden; z-index:8;
}
.c1{display= "none "}
.c2{display= " "}
#Select1 {
position:relative;
}
</style>
<span id= "dfd ">
<input id= "Text1 " type= "text " value= " " onpropertychange= "getsql(this.value) "/> <span id= "s1 " class= "c1 " > <select id= "Select1 " style= "left:expression(18-this.clientWidth) " onpropertychange= "setValue(this.selectedIndex);this.parentNode.previousSibling.value = this.options[this.selectedIndex].innerText; " style= "width:219px ">
<option> Combox test1 </option>
<option> 1 </option>
<option> 2 </option>
<option> 3 </option>
<option> 4 </option>
</select>
</span>
</span>

<script>
var flag;
//onpropertychange= "document.all.Select1.options[flag].innerText=this.value; "1
function setValue(f)
{
flag = f;
}
function getsql(x)
{
document.getElementById( "s1 ").setAttribute( "className ", "c2 ");
//use ajax connect to sqlserver with param "f "
}
</script>
------解决方案--------------------
另,可以用下这种的存储结构。。这样的话,查找的时候效率会很高。。。的说。。
而且还很方便。
var o_key = function (string, parent) {
//关键字树
this.all = new Object;
this.string = string || " ";
this.parent = parent || null;
};

o_key.prototype.add = function (string) {
//添加关键字
if (string != "\xffEND\xff ") {
var i = string.charAt(0), r = string.substr(1, string.length - 1);
if ( "undefined " == typeof this.all[i])
this.all[i] = new o_key(i, this);
this.all[i].add(r != " " ? r : "\xffEND\xff ");
} else {
this.all[ "\xffEND\xff "] = true;
}
};


var e_key = function (string) {
//返回关键字树引用
var object = new o_key, array = string.split(/,[ ]?/), i = 0;
for (; i < array.length ;)
object.add(array[i ++]);
return object;
};

var show = function (string) {
//显示查找结果
var o = wc, i = 0, s = new Array;
for ( ; i < string.length ; ) {
o = o.all[string.charAt(i ++)];
if ( "undefined " != typeof o) s[s.length] = o.string;
else return " ";
}
return (o.all[ "\xffEND\xff "] ? s.join( " ") : " ");
};
var wc = e_key( "for, while, if, ifs, else, function ");
document.write(show( "for ").fixed());
document.write(show( "functionend ").fixed());
document.write( " <hr \/> ");
document.write(show( "if ").fixed());
document.write(show( "topfunction ").fixed());
  相关解决方案