dedecms首页搜索 添加仿百度下拉框

1:找到uploads/templets/default/head.htm

2:找到

<inputname=”q”type=”text”class=”search-keyword”id=”aa”value=”在这里搜索…”onfocus=”if(this.value==’在这里搜索…’){this.value=”;}” onkeydown=”document.getElementById(‘ssxlk’).style.display=’block’;” oninput=”_getvalue()” onblur=”if(this.value==”){this.value=’在这里搜索…’;}”/>

添加 autocomplete=”off”系统input默认autocomplete为on

3:在相应位置添加一个divid=”ssxlk”;

4:添加javascript代码:

<scripttype=”text/javascript”src=”ajax.js”></script>

<scripttype=”text/javascript”>

function_getvalue()

{

varres=”id=”+document.getElementById(‘aa’).value;

//vargvalue=document.getElementByID().value;

getajax(‘ssxxl.php’,res,b);

}

functionb(a)

{

if(document.getElementById(‘aa’).value==”)

{

document.getElementById(‘ssxlk’).innerHTML=”;

}

else

{

document.getElementById(‘ssxlk’).innerHTML=a;

}

//alert(a);

}

</script>

5:ajax.js页面:

functiongetajax(url,j,responsefunction){

if(url){

varxhr=ajax();

xhr.open(“POST”,url,true);

xhr.onreadystatechange=function(){

if(xhr.readyState==4){

if(xhr.status==200){

responsefunction(unescape(xhr.responseText));

}else{

alert(“页面读取失败”);

}

}

};

xhr.setRequestHeader(“Content-Type”,”application/x-www-form-urlencoded;”);

xhr.send(j);//发送请求

}else{

alert(“未知错误,请查识”);

}

}

functionajax(){

varhttp_request;

if(window.XMLHttpRequest){

http_request=newXMLHttpRequest();

if(http_request.overrideMimeType){

http_request.overrideMimeType(“text/xml”);

}

}elseif(window.ActiveXObject){

try{

http_request=newActiveXObject(“Msxml2.XMLHttp”);

}catch(e){

try{

http_request=newActiveXobject(“Microsoft.XMLHttp”);

}catch(e){

}

}

}

if(!http_request){

window.alert(“创建XMLHttp对象失败!”);

returnfalse;

}

returnhttp_request;

}

6:ssxxl.php页面

<?php

mysql_connect(‘localhost’,’root’,’root’);

mysql_select_db(‘dedecms’);

mysql_query(‘setnamesutf8’);

$sql=”select`typename`from`dede_arctype`where`typename`like’%”.$_POST[‘id’].”%’limit0,9;”;

//print_r($sql);

$result=mysql_query($sql);

if($row=mysql_fetch_array($result))

{

do

{

echo$row[0];

echo”<br/>”;

}

while($row=mysql_fetch_array($result));

}

//echo’aaaaaa’;

?>

页面效果为:

家门前的那条小路,到底通向了什么样的远方呢?

dedecms首页搜索 添加仿百度下拉框

相关文章:

你感兴趣的文章:

标签云: