ecshop搜索栏效果如下

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

  1. /*搜索滑动效果*/
  2. .Menu {
  3. position:absolute;
  4. top:30px;
  5. left:7px;
  6. width:150px;
  7. height:auto;
  8. z-index:1;
  9. background:#FFF;
  10. border:1px solid #000;
  11. display:none;
  12. }
  13. .Menu2 {
  14. position: absolute;
  15. left:0;
  16. top:0;
  17. width:100%;
  18. height:auto;
  19. overflow:hidden;
  20. z-index:1;
  21. }
  22. .Menu2 ul{margin:0;padding:0}
  23. .Menu2 ul li{width:100%;height:25px;line-height:25px;text-indent:15px;
  24. border-bottom:1px dashed #ccc;color:#666;cursor:pointer;background:#FFF;
  25. change:expression(
  26. this.onmouseover=function(){
  27. this.style.background="#F2F5EF";
  28. },
  29. this.onmouseout=function(){
  30. this.style.background="";
  31. }
  32. )
  33. }
  34. input{width:200px}
  35. .form{width:200px;height:auto;}
  36. .form div{position:relative;top:0;left:0;margin-bottom:5px}

复制代码

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

  1. <script type="text/javascript">
  2. function showAndHide(obj,types,text){
  3. var Layer=window.document.getElementById(obj);
  4. switch(types){
  5. case "show":
  6. if(text!='')
  7. {
  8. Layer.style.display="block";
  9. Ajax.call('search_div.php', 'act=search&text=' + text, changesumResp**e, 'GET', 'JSON');
  10. }
  11. break;
  12. case "hide":
  13. Layer.style.display="none";
  14. }
  15. }
  16. function getValue(obj,str){
  17. var input=window.document.getElementById(obj);
  18. input.value=str;
  19. }
  20. function changesumResp**e(res)
  21. {
  22. var a='';
  23. for (var i = 0; i < res.content.length; i++)
  24. {
  25. a += "<li onmousedown=getValue('keyword','" + res.content[i].goods_name + "')>" + res.content[i].goods_name + "</li>";
  26. }
  27. // alert(a);
  28. document.getElementById('show_stock').innerHTML = a;
  29. }
  30. </script>

复制代码

我们输入框的代码

  1. <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;"/>
  2. <div class="Menu" id="List1">
  3. <div class="Menu2">
  4. <ul style="padding:0px; margin:0px;" id="show_stock">
  5. </ul>
  6. </div>
  7. </div>

复制代码

ajax请求php的代码

search_div.php

  1. <?php
  2. define('IN_ECS', true);
  3. require(dirname(__FILE__) . '/includes/init.php');
  4. require(dirname(__FILE__) . '/admin/includes/lib_main.php');
  5. if($_REQUEST['act'] == 'search'){
  6. $keywords = json_str_iconv(trim($_GET['text']));
  7. $sql = "SELECT goods_name,goods_id FROM " . $GLOBALS['ecs']->table('goods')." where goods_name like '%$keywords%'";
  8. $brand_array = $GLOBALS['db']->getall($sql);
  9. foreach($brand_array as $ids =>$value)
  10. {
  11. $brand_array[$ids]['goods_name'] = sub_str_xaphp($brand_array[$ids]['goods_name'],5);
  12. }
  13. make_json_result($brand_array);
  14. }
  15. function sub_str_xaphp($str, $length = 0, $append = true)
  16. {
  17. $str = trim($str);
  18. $strlength = strlen($str);
  19. if ($length == 0 || $length >= $strlength)
  20. {
  21. return $str;
  22. }
  23. elseif ($length < 0)
  24. {
  25. $length = $strlength + $length;
  26. if ($length < 0)
  27. {
  28. $length = $strlength;
  29. }
  30. }
  31. if (function_exists('mb_substr'))
  32. {
  33. $newstr = mb_substr($str, 0, $length, EC_CHARSET);
  34. }
  35. elseif (function_exists('iconv_substr'))
  36. {
  37. $newstr = iconv_substr($str, 0, $length, EC_CHARSET);
  38. }
  39. else
  40. {
  41. //$newstr = trim_right(substr($str, 0, $length));
  42. $newstr = substr($str, 0, $length);
  43. }
  44. if ($append && $str != $newstr)
  45. {
  46. $newstr .= '';
  47. }
  48. return $newstr;
  49. }
  50. ?>

复制代码

在商品少的情况下 我们之间查询 如果多了,最模板建议修改程序

ecshop搜索出现相关商品的效果滑动下拉效果的更多相关文章

  1. jQuery手写几个常见的滑动下拉菜单 分分秒秒学习JS

    一般的企业网站再我们再实际工作中,有些特效,用jQuery来做,显得极其简单,除非一些大的公司,需要封装自己的类. 今天,我们讲解jQuery入门知识,来写几个简单jQuery滑动下拉菜单.感受一下j ...

  2. jQuery实现折叠下拉效果

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  3. Android 聊天表情输入、表情翻页带效果、下拉刷新聊天记录

    经过一个星期的折腾,最终做完了这个Android 聊天表情输入.表情翻页带效果.下拉刷新聊天记录.这仅仅是一个单独聊天表情的输入,以及聊天的效果实现.由于我没有写server,所以没有两方聊天的效果. ...

  4. Easy UI combobox实现类似 Select2的效果,下拉带搜索框

    一直在开发一个新系统,其中用Easy UI作为前端框架,少不了用 combobox做为一个 下拉控件,它支持 可编辑 模糊本地数据过滤,也可支持 不可编辑 下拉 选择的功能: $('#ID' ).co ...

  5. MVC身份验证.MVC过滤器.MVC6关键字Task,Async.前端模拟表单验证,提交.自定义匿名集合.Edge导出到Excel.BootstrapTree树状菜单的全选和反选.bootstrap可搜索可多选可全选下拉框

    1.MVC身份验证. 有两种方式.一个是传统的所有控制器继承自定义Control,然后再里面用MVC的过滤器拦截.所以每次网站的后台被访问时.就会先走入拦截器.进行前端和后端的验证 一个是利用(MVC ...

  6. Android抽屉(SlidingDrawer --类似android通知栏下拉效果)

    Android抽屉(SlidingDrawer)的实现发 - 红黑联盟http://www.2cto.com/kf/201301/182507.html 可动态布局的Android抽屉之基础http: ...

  7. 第六章 使用 Bootstrap Typeahead 组件(百度下拉效果)(续)

    官方:http://twitter.github.io/typeahead.js/ 示例:http://twitter.github.io/typeahead.js/examples/(本文展示:Op ...

  8. html、css实现导航栏5种常用下拉效果

    实现的效果:鼠标移入按钮时按钮中的内容就会出现,分别展示不同的出现效果.效果难点:不使用JavaScript,那这个效果的难点就是在于:hover伪类的掌控,以及考验对html的结构掌握. 1. ht ...

  9. iosselect:一个js picker项目,在H5中实现IOS的下拉效果

    iosselect是在webapp下的一个picker组件,可以轻松实现各类选择器效果.比如地区选择 时间选择 日期选择等. 下面是一个地址选择器demo截图,可以访问:http://zhoushen ...

随机推荐

  1. python_遇到问题

    1. [出现问题]:cx_Oracle.DatabaseError: ORA-24315: 非法的属性类型 [原因]:是因为版本不兼容,检查了一下环境,我的oracle client是10g的,但我安 ...

  2. Vue.2.0.5-Vue 实例

    构造器 每个 Vue.js 应用都是通过构造函数 Vue 创建一个 Vue 的根实例 启动的: var vm = new Vue({ // 选项 }) 虽然没有完全遵循 MVVM 模式, Vue 的设 ...

  3. 文本属性Attributes

    1.NSKernAttributeName: @10 调整字句 kerning 字句调整 2.NSFontAttributeName : [UIFont systemFontOfSize:_fontS ...

  4. 数据块损坏(block corruption)

    分为物理损坏和逻辑损坏-物理损坏一般指数据块头部不可以访问.数据块校验值不合法,数据块格式不再是oracle承认的格式-逻辑损坏一般是在物理性结构完整的情况下,数据的内容在含义上不正确,比如保存了不允 ...

  5. ios提示框,自动消失

    -(void)click { NSString *showMsg = @"点击我,开始提示"; int width = showMsg.length * 20; UIWindow ...

  6. Autowired注解的妙用---在Controller里的构造函数里获取需要注入的对象

    /*@Resource private Observer<TaxiObserverVo> taxiPushObserver; @Resource private Observer<T ...

  7. NSCoding归档

    大家都知道ios中数据持久化的方式有plist sqlite coredata nscoding 而nscoding不需要关心模型属性有多少个,是什么类型,不需要定义归档文件的规则. 下面给个类大家用 ...

  8. G面经prepare: Pattern Match

    设定一个pattern 把 'internationalization' 变成 'i18n', 比如word是house,pattern可以是h3e, 3se, 5, 1o1s1等, 给pattern ...

  9. AIR 14 Beta - Missing builtin type Object 解决方法

    使用AIR SDK14 时候出现 Missing builtin type Object 的问题 参考 https://forums.adobe.com/thread/1483159 下载最新的Fla ...

  10. CentOS 7 安装Dukto(局域网通信工具)

    rmp包 http://download.opensuse.org/repositories/home:/colomboem/CentOS_7/x86_64/dukto-6.0-13.1.x86_64 ...