x
 
<!DOCTYPE html>
<html>
<head>
<script>
function showHint(str) {
  if (str.length == 0) { 
    document.getElementById("txtHint").innerHTML = "";
    return;
  } else {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
        document.getElementById("txtHint").innerHTML = this.responseText;
      }
    }
    xmlhttp.open("GET", "/demo/php/gethint.php?q="+str, true);
    xmlhttp.send();
  }
}
</script>
</head>
<body>
<p><b>在下面的输入框中开始输入名字:</b></p>
<form action="">
  <label for="fname">名字:</label>
  <input type="text" id="fname" name="fname" onkeyup="showHint(this.value)">
</form> 
<p>建议:<span id="txtHint"></span></p>
</body>
</html>