自动建议列表框

Hi i have the following auto-suggestion box set up and i want to select the outputs with keyboard and mouse. how can i do that?

Javascript code:

 function showResult(string) {

     if (string.lenght==0) {
         document.getElementById("livesearch").innerHTML="";
         document.getElementById("livesearch").style.border="0px";
         return;
     }
     if (window.XMLHttpRequest) {
         // code for IE7+, Firefox, Chrome, Opera, Safari
         xmlhttp=new XMLHttpRequest();
     } else {
         //code for IE6, IE5
         xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
     }
     xmlhttp.onreadystatechange=function() {
         if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
         }
         document.getElementById("livesearch").innerHTML = xmlhttp.responseText;
         document.getElementById("livesearch").style.border = "1px solid #A5ACB2";
     }
     xmlhttp.open("GET","test.php?q=" + string,true);
     xmlhttp.send();
}

PHP code:

$xmlDoc=new DOMDocument();
//$xmlDoc->load("test.xml");
$xml = simplexml_load_file("test.xml");

//$x=$xmlDoc->getElementsByTagName('datas');

//get the q parameter from URL
$q = $_GET["q"];
if (strlen($q) > 0) {   
    foreach ($xml->datas as $a) {
        $var = $a->attributes();
        $domain = stristr($var,$q);
        echo $domain."
";
        echo "<br/>";
    }
    if (strlen($domain) == 0) {
        echo "no results";
    }

Everything works fine at this point. But I don't know how to interact with the list.

查看全部
weixin_33749242
weixin_33749242
2012/03/05 02:39
  • autocomplete
  • php
  • ajax
  • javascript
  • 点赞
  • 收藏
  • 回答
    私信

1个回复