function chooseIt(obj)//obj是用this传递过来的当前点击对象
{
document.getElementById("search").value=obj.innerHTML;//将选择的内容在文本框中进行填充
document.getElementById("dv").innerHTML="";//清空搜索建议的内容
document.getElementById('dv').style.display = "none";//让搜索建议图层的边框消失
}
function onIt(obj){
obj.style.backgroundColor = "#36F";
}
function outIt(obj){
obj.style.backgroundColor = "#CCC";
}
function init(){
document.getElementById('dv').style.display = "none";
}
function startAjax(obj){
var xhr;
if(window.ActiveXObject){
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
xhr = new XMLHttpRequest();
}
//在发送请求之前,需要知道服务器的地址
var url = "index.PHP?c=user&a=baiduSuggest";
xhr.open("post",url,true);
//设置监听请求状态
xhr.onreadystatechange = callback;
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
if(obj==''){document.getElementById('dv').style.display = "none";}else{
xhr.send("var="+obj);}
function callback(){
if(xhr.readyState ==4){
if(xhr.status==200){
var json = eval('('+xhr.responseText+')');
var str = '';
for(var i=0;i
str += ''+json[i].id+"
";
document.getElementById("dv").style.display = "block";
document.getElementById("dv").innerHTML = str;
}
}
}
}
}
百度一下,你就知道
总结
以上是编程之家为你收集整理的ajax实现百度搜索建议全部内容,希望文章能够帮你解决ajax实现百度搜索建议所遇到的程序开发问题。
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。