Antant10
01-11-2010, 17:12
Сделал на сайте быстрый поиск. Все отлично работает, проблема в одном - не исчезает блок с результатами поиска если кликнуть в любом месте сайта (вне блока)
Этот код в HEAD
<script type="text/javascript" language="javascript">
var req;
function loadXMLDoc(key) {
var url="search.php?keyword="+key;
// Internet Explorer
try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
catch(e) {
try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
catch(oc) { req = null; }
}
// Mozailla/Safari
if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }
// Call the processChange() function when the page has loaded
if (req != null) {
req.onreadystatechange = processChange;
req.open("GET", url, true);
req.send(null);
}
}
function processChange() {
// The page has loaded and the HTTP status code is 200 OK
if (req.readyState == 4 && req.status == 200) {
// Write the contents of this URL to the searchResult layer
getObject("quicksearch").innerHTML = req.responseText;
}
}
function getObject(name) {
var ns4 = (document.layers) ? true : false;
var w3c = (document.getElementById) ? true : false;
var ie4 = (document.all) ? true : false;
if (ns4) return eval('document.' + name);
if (w3c) return document.getElementById(name);
if (ie4) return eval('document.all.' + name);
return false;
}
</script>
Сама форма
<input name="keyword" id="search_area" type="text" onKeyUp="loadXMLDoc(this.value);" autocomplete="off" />
<div id="quicksearch"></div>
CSS-код из файла стилей
#quicksearch {text-align:left; position: absolute; top: 110px; left: 645px; background-color:#FFFFE8; color: #333333; font-size:12px; z-index:500; width:300px; }
#quicksearch ul, #quicksearch li {padding:0; margin:0; border:0; list-style:none;}
#quicksearch li {border-bottom:solid 1px #DEDEDE;}
#quicksearch li a{display:block; padding:4px; text-decoration:none; color:#000000; font-weight:bold;}
#quicksearch li a small{display:block; text-decoration:none; color:#999999; font-weight:normal;}
#quicksearch li a:hover{background:#FFFFCC;}
#quicksearch ul {padding:6px;}
Помогите пожалуйста
Этот код в HEAD
<script type="text/javascript" language="javascript">
var req;
function loadXMLDoc(key) {
var url="search.php?keyword="+key;
// Internet Explorer
try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
catch(e) {
try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
catch(oc) { req = null; }
}
// Mozailla/Safari
if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }
// Call the processChange() function when the page has loaded
if (req != null) {
req.onreadystatechange = processChange;
req.open("GET", url, true);
req.send(null);
}
}
function processChange() {
// The page has loaded and the HTTP status code is 200 OK
if (req.readyState == 4 && req.status == 200) {
// Write the contents of this URL to the searchResult layer
getObject("quicksearch").innerHTML = req.responseText;
}
}
function getObject(name) {
var ns4 = (document.layers) ? true : false;
var w3c = (document.getElementById) ? true : false;
var ie4 = (document.all) ? true : false;
if (ns4) return eval('document.' + name);
if (w3c) return document.getElementById(name);
if (ie4) return eval('document.all.' + name);
return false;
}
</script>
Сама форма
<input name="keyword" id="search_area" type="text" onKeyUp="loadXMLDoc(this.value);" autocomplete="off" />
<div id="quicksearch"></div>
CSS-код из файла стилей
#quicksearch {text-align:left; position: absolute; top: 110px; left: 645px; background-color:#FFFFE8; color: #333333; font-size:12px; z-index:500; width:300px; }
#quicksearch ul, #quicksearch li {padding:0; margin:0; border:0; list-style:none;}
#quicksearch li {border-bottom:solid 1px #DEDEDE;}
#quicksearch li a{display:block; padding:4px; text-decoration:none; color:#000000; font-weight:bold;}
#quicksearch li a small{display:block; text-decoration:none; color:#999999; font-weight:normal;}
#quicksearch li a:hover{background:#FFFFCC;}
#quicksearch ul {padding:6px;}
Помогите пожалуйста