【发布时间】:2014-01-15 03:35:18
【问题描述】:
当用户按下Esc按钮时,我希望建议列表将被关闭。
我该怎么做?
这是我的代码:
-
script_suggestion.php:
<script type="text/javascript"> //document.getElementById("suggestion") function getSuggestion(q) { var ajax; if(window.XMLHttpRequest)//for ie7+, FF, Chrome ajax = new XMLHttpRequest();//ajax object else ajax = new ActiveXObject("Microsoft.XMLHTTP");//for ie6 and previous ajax.onreadystatechange = function() { if(ajax.status === 200 && ajax.readyState === 4) { //if result are not there then don't display them if(ajax.responseText === "") document.getElementById("suggestion").style.visibility = "hidden"; else { document.getElementById("suggestion").style.visibility = "visible"; document.getElementById("suggestion").innerHTML = ajax.responseText; } } }; ajax.open("GET", "suggestion.php?q=" + q, false); ajax.send(); } </script> -
PHP 代码:
<?php include 'script_suggestion.php'; include 'script_close_suggestion_box.php'; ?>
提前致谢。
【问题讨论】:
-
查找 esc 按钮的键码,添加功能以关闭列表。
标签: javascript jquery search-engine