您现在的位置是:首页 > cms教程 > Ecshop商城教程Ecshop商城教程

商城ecshop搜索结果滑动下拉显示相关商品的实现方法

雪柳2023-11-14Ecshop商城教程已有人查阅

导读所需要的样式我们可以 到style.css里:以下代码需要加到输入框普遍 比如page_header.lbi;在商品少的情况下 我们之间查询 如果多了,ECSHOP模板屋建议修改程序

所需要的样式我们可以 到style.css里:

 /*搜索滑动效果*/ .Menu { position:absolute; top:30px; left:7px; width:150px; height:auto; z-index:1; background:#FFF; border:1px solid #000; display:none; } .Menu2 { position: absolute; left:0; top:0; width: ; height:auto; overflow:hidden; z-index:1; } .Menu2 ul{margin:0;padding:0} .Menu2 ul li{width: ;height:25px;line-height:25px;text-indent:15px;              border-bottom:1px dashed #ccc;color:#666;cursor:pointer;background:#FFF;
    change:expression(
     this.onmouseover=function()
{
       this.style.background="#F2F5EF";
     },
     this.onmouseout=function()
{
       this.style.background="";
     }
    )
   }
input{width:200px} .form{width:200px;height:auto;} .form div{position:relative;top:0;left:0;margin-bottom:5px}

以下代码需要加到输入框普遍 比如page_header.lbi

<script type="text/javascript">   function showAndHide(obj,types,text){     var Layer=window.document.getElementById(obj);     switch(types){    case "show":      if(text!='')   {              Layer.style.display="block";     Ajax.call('search_div.php', 'act=search&text=' + text, changesumResp**e, 'GET', 'JSON');    }    break;    case "hide":      Layer.style.display="none"; }   }   function getValue(obj,str){     var input=window.document.getElementById(obj); input.value=str;   }   function changesumResp**e(res) {     var a='';       for (var i = 0; i < res.content.length; i++)       {         a += "<li onmousedown=getValue('keyword','" + res.content[i].goods_name + "')>" + res.content[i].goods_name + "</li>";    }   // alert(a);    document.getElementById('show_stock').innerHTML = a; }     </script>

我们输入框的代码

<input name="keywords" onkeyup="showAndHide('List1','show',this.value);" onblur="showAndHide('List1','hide');" type="text" id="keyword" value="{$search_keywords|escape}" style=" border:0; margin-left:15px;margin-top:5px; width:130px; height:15px;"/> <div class="Menu" id="List1"> <div class="Menu2"> <ul style="padding:0px; margin:0px;" id="show_stock"> </ul> </div> </div> 

ajax请求php的代码search_div.php

<?php define('IN_ECS', true); require(dirname(__FILE__) . '/includes/init.php'); require(dirname(__FILE__) . '/admin/includes/lib_main.php'); if($_REQUEST['act'] == 'search'){   $keywords = json_str_iconv(trim($_GET['text']));   $sql = "SELECT goods_name,goods_id FROM " . $GLOBALS['ecs']->table('goods')." where goods_name like '%$keywords%'";   $brand_array = $GLOBALS['db']->getall($sql);   foreach($brand_array as $ids =>$value)
  {
$brand_array[$ids]['goods_name'] = sub_str_xaphp($brand_array[$ids]['goods_name'],5);
  }
  make_json_result($brand_array); } function sub_str_xaphp($str, $length = 0, $append = true)
{
 $str = trim($str);
 $strlength = strlen($str);
 if ($length == 0 || $length >= $strlength)
 {
  return $str;
 }
 elseif ($length < 0)
 {
  $length = $strlength + $length;
  if ($length < 0)
  {
$length = $strlength;
        }
 }
 if (function_exists('mb_substr'))
 {
        $newstr = mb_substr($str, 0, $length, EC_CHARSET);
 }
 elseif (function_exists('iconv_substr'))
 {
  $newstr = iconv_substr($str, 0, $length, EC_CHARSET);
 }
 else
 {
  //$newstr = trim_right(substr($str, 0, $length));
  $newstr = substr($str, 0, $length);
 }
 if ($append && $str != $newstr)
 {
  $newstr .= '';
 }
 return $newstr; } ?>

在商品少的情况下 我们之间查询 如果多了,ECSHOP代码号建议修改程序

本文标签:

很赞哦! ()

相关源码

  • 帝国CMS7.5小说推荐公众号导航带wap手机站+带采集工具本模板为小说导航类网站设计开发,基于帝国CMS7.5内核构建,针对小说阅读领域的分类聚合需求进行深度优化。通过智能分类系统和用户行为分析,实现小说资源的精准推荐与导航功能。查看源码
  • (自适应)居家生活日用品纸盘纸盒纸杯卫生纸巾生产厂家pbootcms模板为纸品生产企业打造的现代化展示平台,自动适应各种设备屏幕,确保浏览体验一致,完善的SEO功能,提升网站曝光度,基于PbootCMS构建,源码开放可定制。查看源码
  • (自适应)光伏测试仪器电站运维设备网站源码免费下载本模板为光伏检测设备与电站运维服务企业设计,采用PbootCMS内核开发,具备完整的设备展示、技术文档管理及客户服务功能模块。通过自适应结构与SEO优化框架,有效提升企业在移动端和搜索引擎中的专业形象。查看源码
  • (自适应响应式)APP应用程序软件介绍落地页源码免费下载该模板为营销技术从业者设计,提供专业的内容展示平台。采用响应式布局,适配软件介绍、APP推广等营销场景,通过可视化后台可快速搭建符合行业特性的展示网站。查看源码
  • (自适应)餐具英文外贸生活用品带下载功能网站模板免费下载为餐具及生活用品外贸企业打造的响应式网站模板,基于PbootCMS内核开发。突出产品展示与多语言支持特性,通过自适应设计确保更好客户在手机、平板、电脑等设备上获得一致浏览体验。查看源码
  • 帝国cms7.5品牌连锁店招商加盟商机网站模版源码本模板为招商加盟、创业投资、品牌连锁等商业领域设计,采用帝国CMS7.5内核构建,整体风格简洁大气,突出商业信任感与专业度,适合各类招商加盟项目展示、品牌连锁店宣传等商业应用场景。查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐