通过Ajax操作Dom:
1 if(xmlHttp.readyState == 4){ 2 if(xmlHttp.status == 200){ 3 var sobj = document.getElementById("suggest"); 4 var str = xmlHttp.responseText.split("-"); 5 var suggest = ""; 6 if(str.length >0 && str[0].length > 0){ 7 for(var i=0; i<str.length; i++){ 8 suggest += "<div class='suggest_link' " + 9 " onmouseover="this.className='suggest_link_over'" " + 10 " onmouseout="this.className='suggest_link'" >"+str[i]+"</div>" 11 } 12 sobj.innerHTML = suggest; 13 sobj.style.display = "block"; 14 }else{ 15 sobj.style.display = "none"; 16 } 17 } 18 }
把数据库中的数据显示在界面上。