<script type="text/javascript">
j(document).ready(function(){
// 初始化JSUGGEST
jsuggest.init("text");
//或者用下面的方法,设置下拉框高度
//jsuggest.init("text",200);
})
function go(event, value){
event= event ? event : (window.event ? window.event : arguments[0]);
var url = "url?suggestInput="+encodeURIComponent(value);//url是具体的action或jsp地址等,返回值是以逗号分隔的字符串
goSuggestInput(event,url,value);
}
function goSuggestInput(evnet,url,value){
if (value == ""){
// 如果输入框为空隐藏下拉框
jsuggest.hide();
return false;
}
// 确保evt是一个有效的事件
if (!evnet && window.event)
{
evnet = window.event;
}
var key = evnet.keyCode;
if (key == 38 || key == 40 || key == 13 || key == 27){
return false;
}
j.ajax({
type: "post",
url:url,
dataType: "text",
cache: "false",
beforeSend: function(XMLHttpRequest){
},
success: function(data, textStatus){
// 对下拉框添加数据
jsuggest.create(data);
},
complete: function(XMLHttpRequest, textStatus){
},
error: function(){
alert("对不起,服务器忙!");
}
});
}
</script>
您可能感兴趣的文章: