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

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

2: 找到 

<input name="q" type="text"  class="search-keyword" id="aa" value="在这里搜索..." οnfοcus="if(this.value=='在这里搜索...'){this.value='';}" 

   οnkeydοwn="document.getElementById('ssxlk').style.display= 'block';"

   οninput="_getvalue()"

   οnblur="if(this.value==''){this.value='在这里搜索...';}" />

添加   autocomplete="off" 系统input 默认autocomplete on 

3:在相应位置添加一个div  id="ssxlk"

4:添加javascript代码:

<script type="text/javascript" src="ajax.js"></script>

<script type="text/javascript" >

function _getvalue()

{

var res = "id="+document.getElementById('aa').value;

//var gvalue =  document.getElementByID().value;

getajax('ssxxl.php',res,b);

 

}

function b(a)

{

 

if(document.getElementById('aa').value=='')

{

document.getElementById('ssxlk').innerHTML='';

}

else

{

 

document.getElementById('ssxlk').innerHTML=a;

}

//alert(a);

}

</script>

 

5ajax.js页面:

 

function getajax(url,j,responsefunction){

if(url){

 

var xhr=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("未知错误,请查识");

}

}

function ajax(){

var http_request;

if(window.XMLHttpRequest){

http_request=new XMLHttpRequest();

if(http_request.overrideMimeType){

http_request.overrideMimeType("text/xml");

}

}else if(window.ActiveXObject){

try{

http_request=new ActiveXObject("Msxml2.XMLHttp");

}catch(e){

try{

http_request=new ActiveXobject("Microsoft.XMLHttp");

}catch(e){

}

}

}

if(!http_request){

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

return false;

}

return http_request;

}

 

 

 

 

6ssxxl.php页面

<?php

mysql_connect('localhost','root','root');

mysql_select_db('dedecms');

mysql_query('set names utf8');

 

$sql = "select `typename` from `dede_arctype` where `typename` like '%".$_POST['id']."%' limit 0,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';

?>

页面效果为:

转载于:https://www.cnblogs.com/siichen/p/3668989.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值