JS仿百度搜索自动提示框匹配查询功能

使用js实现文本框模糊查询自动提示 使用js实现模糊查询自动提示 使用js实现模糊查询自动提示 立即下载

1. 添加动态加载css文件 不需要引入css css全部在JS动态生成。
2. 不需要额外的标签 只需要一个input输入框 并且默认指定一个class类名为 "inputElem" 当然也可以自己配置参数 还需要一个当前父级容器增加一个默认类名 parentCls(也可以自己配置),因为输入框匹配值后需要一个隐藏域 所以需要隐藏域增加一个class "hiddenCls" 当然也支持自己配置参数。

如下代码:

复制代码 代码如下:

<div class="parentCls">
        <div style="width:200px;height:26px;border:1px solid #ccc;">
            <input type="text" class="inputElem" style="width:200px;height:26px;line-height:26px;"/>
        </div>
        <input type="hidden" class="hiddenCls"/>
    </div>


    <div class="parentCls">
        <div style="width:200px;height:26px;border:1px solid #ccc;">
            <input type="text" class="inputElem" style="width:200px;height:26px;line-height:26px;"/>
        </div>
        <input type="hidden" class="hiddenCls"/>
    </div>

3. 支持页面上有多个输入框。

4. 支持鼠标点击和 键盘 上移和下移键操作 类似于百度输入框。
页面上所有的标签都是动态的生成的,不需要额外的标签。如上面的 只需要input标签 其他的div标签不依赖 只需要父级元素增加class "parentCls"(当然可以自己配置类名),
及要传给后台开发人员的隐藏域输入框 增加一个class "hiddenCls" 当然也可以自动配置参数。

我的模糊查询匹配的需求是这样的:
1. 每keyup时候 点击或者键盘上移下移操作 输入框填充用户名/工号 隐藏域填充工号 发请求 服务器返回数据 渲染出来。当然 隐藏域填充工号 值是form表单提交时候 后台要拿到提交过来的工号 所以需要这么一个隐藏域。
2. 当用户直接在输入框输入值时候 并没有键盘上移下移 或者 点击下拉框某一项时候 当鼠标失去焦点时候(blur) 当前输入框值为空 隐藏域值为空,这样做的目的 是为了防止上次form提交过后的数据仍然保存在隐藏域里面 当用户重新输入的时候 用户也并没有操作键盘上下移操作或者点击操作 再点击提交按钮时(失去焦点),那么值为空 隐藏域值为空 这样防止搜索出来不是用户输入的那个东东。
3. 当用户点击某一项时候 或者 上移下移时候 输入框动态的生成值 且输入框值现在不能重新输入 只有当点击输入框x的时候 才可以重新输入。
4. 已经遗留输入框可以多选的接口 目前还未完善输入框多选的操作。
5. 禁止ctrl+v 或者右键 粘贴操作。

下面HTML代码如下:

复制代码 代码如下:

<div class="parentCls">
        <div style="width:200px;height:26px;border:1px solid #ccc;">
            <input type="text" class="inputElem" style="width:200px;height:26px;line-height:26px;"/>
        </div>
        <input type="hidden" class="hiddenCls"/>
    </div>


    <div class="parentCls">
        <div style="width:200px;height:26px;border:1px solid #ccc;">
            <input type="text" class="inputElem" style="width:200px;height:26px;line-height:26px;"/>
        </div>
        <input type="hidden" class="hiddenCls"/>
    </div>

    <input type="button" value="提交"/>

JS代码如下:

复制代码 代码如下:

/**
 * JS 模糊查询
 * @author tugenhua
 * @date 2013-11-19
 * @param 1.当前的input add targetCls
 * 2. 隐藏域里面统一增加同类名 叫 hiddenCls
 * 3. 在各个父级元素上 添加类名 parentCls
 */

 function AutoComplete (options) {
     this.config = {
        targetCls          : '.inputElem',          // 输入框目标元素
        parentCls          : '.parentCls',          // 父级类
        hiddenCls          : '.hiddenCls',          // 隐藏域input
        searchForm         :'.jqtransformdone',     //form表单
        hoverBg            : 'hoverBg',             // 鼠标移上去的背景
        outBg              : 'outBg',               // 鼠标移下拉的背景
        isSelectHide       : true,                 // 点击下拉框 是否隐藏
        url                : '',                    // url接口
        height             : 0,                     // 默认为0 不设置的话 那么高度自适应
        manySelect         : false,                 // 输入框是否多选 默认false 单选
        renderHTMLCallback : null,                  // keyup时 渲染数据后的回调函数
        callback           : null,                  // 点击某一项 提供回调
        closedCallback     : null                   // 点击输入框某一项x按钮时 回调函数
     };

     this.cache = {
        currentIndex        : -1,
        oldIndex            : -1,
        inputArrs           : []                 // 多选时候 输入框值放到数组里面去
     };
     this.init(options);
 }

 AutoComplete.prototype = {

    constructor: AutoComplete,
    init: function(options) {

        this.config = $.extend(this.config, options || {});
        var self = this,
            _config = self.config,
            _cache = self.cache;

         // 鼠标点击输入框时候
          $(_config.targetCls).each(function(index,item) {

              /*
               *  禁止 ctrl+v 和 黏贴事件
               */
              $(item).unbind('paste');
              $(item).bind('paste',function(e){
                  e.preventDefault();
                  var target = e.target,
                      targetParent = $(target).closest(_config.parentCls);
                  $(this).val('');
                  $(_config.hiddenCls,targetParent) && $(_config.hiddenCls,targetParent).val('');
              });

              $(item).keyup(function(e){
                  _cache.inputArrs = [];
                  var targetVal = $.trim($(this).val()),
                      keyCode = e.keyCode,
                      elemHeight = $(this).outerHeight(),
                      elemWidth = $(this).outerWidth();

                  // 如果输入框值为空的话 那么隐藏域的value清空掉
                  if(targetVal == '') {
                       var curParents = $(this).closest(_config.parentCls);
                       $(_config.hiddenCls,curParents).val('');
                  }
                  var targetParent = $(this).parent();
                  $(targetParent).css({'position':'relative'});

                  if($('.auto-tips',targetParent).length == 0) {
                      // 初始化时候 动态创建下拉框容器
                     $(targetParent).append($('<div class="auto-tips hidden"></div>'));
                     $('.auto-tips',targetParent).css({'position':'absolute','top':elemHeight,'left':'0px','z-index':999,'width':elemWidth,'border':'1px solid #ccc'});
                  }

                 
                  var curIndex = self._keyCode(keyCode);
                  if(curIndex > -1){
                          self._keyUpAndDown(targetVal,e,targetParent);
                    }else {
                         if(targetVal != '') {
                            self._doPostAction(targetVal,targetParent);
                         }

                    }
              });

              // 失去焦点时 如果没有点击 或者上下移时候 直接输入 那么当前输入框值情况 隐藏域值情况
              $(item).blur(function(e){
                  var target = e.target,
                      targetParent = $(target).closest(_config.parentCls);
                  if($(this).attr('up') || $(this).attr('down')) {
                     return;
                  }else {
                     $(this).val('');
                     $(_config.hiddenCls,targetParent).val('');
                  }
              });

          });

          // 阻止form表单默认enter键提交
          $(_config.searchForm).each(function(index,item) {
               $(item).keydown(function(e){
                    var keyCode = e.keyCode;
                    if(keyCode == 13) {
                        return false;
                    }
               });
          });

          // 点击文档
          $(document).click(function(e){
             e.stopPropagation();
             var target = e.target,
                 tagParent = $(target).parent(),
                 attr = $(target,tagParent).closest('.auto-tips');

             var tagCls = _config.targetCls.replace(/^\./,'');

             if(attr.length > 0 || $(target,tagParent).hasClass(tagCls)) {
                return;
             }else {
                $('.auto-tips').each(function(index,item){
                    !$(item,tagParent).hasClass('hidden') && $(item,tagParent).addClass('hidden');
                });

             }
          });

          var stylesheet = '.auto-tips { margin: 0 1px; list-style: none;height:auto !important;padding: 0px;position:absolute; border:1px solid #ccc; top:27px; left:0; z-index:999; width:100%;background:#fff !important;}' +
                           '.auto-tips p {overflow: hidden;margin: 1px 0;padding: 5px 5px;border-bottom: 1px solid #e7e7e7;color: #666;text-decoration: none;line-height: 23px;white-space: nowrap;cursor: pointer;zoom: 1;}' +
                           '.auto-tips p img{ vertical-align:middle;float:left;}' +
                           '.create-input{line-height:26px,padding-left:3px;}' +
                           '.create-input span{margin-top:1px;height:24px;float:left;}' +
                           '.create-input span i,.auto-tips span a{font-style:normal;float:left;cursor:default;}' +
                           '.create-input span a{padding:0 8px 0 3px;cursor:pointer;}' +
                           '.auto-tips p.hoverBg {background-color: #669cb6;color: #fff;cursor: pointer;}' +
                           '.hidden {display:none;}';

          this._addStyleSheet(stylesheet);

    },
    /**
     * 键盘上下键操作
     */
    _keyUpAndDown: function(targetVal,e,targetParent) {
        var self = this,
            _cache = self.cache,
            _config = self.config;

        // 如果请求成功后 返回了数据(根据元素的长度来判断) 执行以下操作
        if($('.auto-tips p',targetParent) && $('.auto-tips p',targetParent).length > 0) {

            var plen = $('.auto-tips p',targetParent).length,
                keyCode = e.keyCode;
                _cache.oldIndex = _cache.currentIndex;

            // 上移操作
            if(keyCode == 38) {
                if(_cache.currentIndex == -1) {
                    _cache.currentIndex = plen - 1;
                }else {
                    _cache.currentIndex = _cache.currentIndex - 1;
                    if(_cache.currentIndex < 0) {
                        _cache.currentIndex = plen - 1;
                    }
                }
                if(_cache.currentIndex !== -1) {

                    !$('.auto-tips .p-index'+_cache.currentIndex,targetParent).hasClass(_config.hoverBg) &&
                    $('.auto-tips .p-index'+_cache.currentIndex,targetParent).addClass(_config.hoverBg).siblings().removeClass(_config.hoverBg);
                    var curAttr = $('.auto-tips .p-index'+_cache.currentIndex,targetParent).attr('data-html'),
                        embId = $('.auto-tips .p-index'+_cache.currentIndex,targetParent).attr('embId');

                    // 判断是否是多选操作 多选操作 暂留接口
                    if(_config.manySelect) {
                        _cache.inputArrs.push(curAttr);
                        _cache.inputArrs = self._unique(_cache.inputArrs);
                        self._manySelect(targetParent);
                    }else {
                        $(_config.targetCls,targetParent).val(curAttr);
                        // 上移操作增加一个属性 当失去焦点时候 判断有没有这个属性
                        if(!$(_config.targetCls,targetParent).attr('up')){
                            $(_config.targetCls,targetParent).attr('up','true');
                        }
                       

                        var pCls = $(_config.targetCls,targetParent).closest(_config.parentCls);
                        $(_config.hiddenCls,pCls).val(embId);

                        self._createDiv(targetParent,curAttr);
                        self._closed(targetParent);
                        // hover
                        self._hover(targetParent);
                    }

                }

            }else if(keyCode == 40) { //下移操作
                if(_cache.currentIndex == plen - 1) {
                    _cache.currentIndex = 0;
                }else {
                    _cache.currentIndex++;
                    if(_cache.currentIndex > plen - 1) {
                        _cache.currentIndex = 0;
                    }
                }
                if(_cache.currentIndex !== -1) {

                    !$('.auto-tips .p-index'+_cache.currentIndex,targetParent).hasClass(_config.hoverBg) &&
                    $('.auto-tips .p-index'+_cache.currentIndex,targetParent).addClass(_config.hoverBg).siblings().removeClass(_config.hoverBg);
                    var curAttr = $('.auto-tips .p-index'+_cache.currentIndex,targetParent).attr('data-html'),
                        embId = $('.auto-tips .p-index'+_cache.currentIndex,targetParent).attr('embId');

                   
                    // 判断是否是多选操作 多选操作 暂留接口
                    if(_config.manySelect) {
                        _cache.inputArrs.push(curAttr);
                        _cache.inputArrs = self._unique(_cache.inputArrs);
                        self._manySelect(targetParent);
                    }else {
                        $(_config.targetCls,targetParent).val(curAttr);

                        // 下移操作增加一个属性 当失去焦点时候 判断有没有这个属性
                        if(!$(_config.targetCls,targetParent).attr('down')){
                            $(_config.targetCls,targetParent).attr('down','true');
                        }

                        var pCls = $(_config.targetCls,targetParent).closest(_config.parentCls);
                        $(_config.hiddenCls,pCls).val(embId);
                        self._createDiv(targetParent,curAttr);
                        self._closed(targetParent);
                        // hover
                        self._hover(targetParent);
                    }

                }
            }else if(keyCode == 13) { //回车操作
                var curVal = $('.auto-tips .p-index'+_cache.oldIndex,targetParent).attr('data-html');
                $(_config.targetCls,targetParent).val(curVal);
                if(_config.isSelectHide) {
                    !$(".auto-tips",targetParent).hasClass('hidden') && $(".auto-tips",targetParent).addClass('hidden');
                }

                _cache.currentIndex = -1;
                _cache.oldIndex = -1;

            }
        }
    },
    // 键码判断
    _keyCode: function(code) {
        var arrs = ['17','18','38','40','37','39','33','34','35','46','36','13','45','44','145','19','20','9'];
        for(var i = 0, ilen = arrs.length; i < ilen; i++) {
            if(code == arrs[i]) {
                return i;
            }
        }
        return -1;
    },
    _doPostAction: function(targetVal,targetParent) {

        var  self = this,
             _cache = self.cache,
             _config = self.config,
             url = _config.url;

        // 假如返回的数据如下:
        var results = [{lastName:'tugenhua',emplId:'E0987',image:''},{lastName:'tugenhua',emplId:'E0988',image:''},{lastName:'tugenhua',emplId:'E0989',image:''}];
        self._renderHTML(results,targetParent);
        self._executeClick(results,targetParent);
       /** $.get(url+"?keyword="+targetVal+"×tamp="+new Date().getTime(),function(data){
            var ret = $.parseJSON(data.content),
                results = ret.results;
            if(results.length > 0) {
                self._renderHTML(results,targetParent);
                self._executeClick(results,targetParent);
            }else {
                !$('.auto-tips',targetParent).hasClass('hidden') && $('.auto-tips',targetParent).addClass("hidden");
                $('.auto-tips',targetParent).html('');

            }
        });**/

    },
    _renderHTML: function(ret,targetParent) {
        var self = this,
            _config = self.config,
            _cache = self.cache,
            html = '';

        for(var i = 0, ilen = ret.length; i < ilen; i+=1) {
            html += '<p  data-html = "'+ret[i].lastName+'('+ret[i].emplId+')" embId="'+ret[i].emplId+'" class="p-index'+i+'">' +
                       '<img src="'+ret[i].image+'" style="margin-right:5px;" height="25" width="25" title="" alt="">' +
                       '<span>'+ret[i].lastName+'('+ret[i].emplId+')</span>' +
                    '</p>';
        }
        // 渲染值到下拉框里面去
        $('.auto-tips',targetParent).html(html);
         $('.auto-tips',targetParent).hasClass('hidden') && $('.auto-tips',targetParent).removeClass('hidden');
        $('.auto-tips p:last',targetParent).css({"border-bottom":'none'});

        _config.renderHTMLCallback && $.isFunction(_config.renderHTMLCallback) && _config.renderHTMLCallback();

        // 出现滚动条 计算p的长度 * 一项p的高度 是否大于 设置的高度 如是的话 出现滚动条 反之
        var plen = $('.auto-tips p',targetParent).length,
            pheight = $('.auto-tips p',targetParent).height();

        if(_config.height > 0) {
            if(plen*pheight > _config.height) {
                $('.auto-tips',targetParent).css({'height':_config.height,'overflow':'auto'});
            }else {
                $('.auto-tips',targetParent).css({'height':'auto','overflow':'auto'});
            }
        }
    },
    /**
      * 当数据相同的时 点击对应的项时 返回数据
      */
    _executeClick: function(ret,targetParent) {
        var self = this,
            _config = self.config,
            _cache = self.cache;
         $('.auto-tips p',targetParent).unbind('click');
         $('.auto-tips p',targetParent).bind('click',function(e){
              var dataAttr = $(this).attr('data-html'),
                  embId = $(this).attr('embId');

              // 判断是否多选
              if(_config.manySelect) {
                  _cache.inputArrs.push(dataAttr);
                  _cache.inputArrs = self._unique(_cache.inputArrs);
                  self._manySelect(targetParent);
              }else {
                 $(_config.targetCls,targetParent).val(dataAttr);
                 var parentCls = $(_config.targetCls,targetParent).closest(_config.parentCls),
                     hiddenCls = $(_config.hiddenCls,parentCls);
                 $(hiddenCls).val(embId);
                 self._createDiv(targetParent,dataAttr);

                 // hover
                 self._hover(targetParent);

                 !$(_config.targetCls,targetParent).hasClass('hidden') && $(_config.targetCls,targetParent).addClass('hidden');
              }
              self._closed(targetParent);
              if(_config.isSelectHide) {
                  !$('.auto-tips',targetParent).hasClass('hidden') && $('.auto-tips',targetParent).addClass('hidden');
              }
              _config.callback && $.isFunction(_config.callback) && _config.callback();
         });

         // 鼠标移上效果
         $('.auto-tips p',targetParent).hover(function(e){
             !$(this,targetParent).hasClass(_config.hoverBg) &&
             $(this,targetParent).addClass(_config.hoverBg).siblings().removeClass(_config.hoverBg);
         });
    },
    _hover: function(targetParent){
        $('.create-input span',targetParent).hover(function(){
            $(this).css({"background":'#ccc','padding-left':'0px'});
        },function(){
             $(this).css({"background":''});
        });
    },
    // 动态的创建div标签 遮住input输入框
    _createDiv: function(targetParent,dataAttr){
         var self = this,
             _config = self.config;
         var iscreate = $('.create-input',targetParent);

         // 确保只创建一次div
         if(iscreate.length > 0) {
            $('.create-input',targetParent).remove();
         }
         $(targetParent).prepend($('<div class="create-input"><span><i></i></span></div>'));
         $('.create-input span i',targetParent).html(dataAttr);
         $(_config.targetCls,targetParent).val(dataAttr);
         $('.create-input span',targetParent).append('<a class="alink">X</a>');
         $('.alink',targetParent).css({'float':'left','background':'none'});
    },
    // X 关闭事件
    _closed: function(targetParent){
         var self = this,
             _config = self.config;
         /*
          * 点击X 关闭按钮
          * 判断当前输入框有没有up和down属性 有的话 删除掉 否则 什么都不做
          */
          $('.alink',targetParent).click(function(){
             $('.create-input',targetParent) && $('.create-input',targetParent).remove();
             $(_config.targetCls,targetParent) && $(_config.targetCls,targetParent).hasClass('hidden') &&
             $(_config.targetCls,targetParent).removeClass('hidden');
             $(_config.targetCls,targetParent).val('');
             //清空隐藏域的值
             var curParent = $(_config.targetCls,targetParent).closest(_config.parentCls);
             $(_config.hiddenCls,curParent).val('');

             var targetInput = $(_config.targetCls,targetParent);
             if($(targetInput).attr('up') || $(targetInput).attr('down')) {
                 $(targetInput).attr('up') && $(targetInput).removeAttr('up');
                 $(targetInput).attr('down') && $(targetInput).removeAttr('down');
             }
             _config.closedCallback && $.isFunction(_config.closedCallback) && _config.closedCallback();
          });
    },
    /*
     * 数组去重复
     */
    _unique: function(arrs) {
        var obj = {},
            newArrs = [];
        for(var i = 0, ilen = arrs.length; i < ilen; i++) {
            if(obj[arrs[i]] != 1) {
                newArrs.push(arrs[i]);
                obj[arrs[i]] = 1;
            }
        }
        return newArrs;
    },
    /*
     * 输入框多选操作
     */
    _manySelect: function(targetParent) {
        var self = this,
            _config = self.config,
            _cache = self.cache;
        if(_cache.inputArrs.length > 0) {
            $(_config.targetCls,targetParent).val(_cache.inputArrs.join(','));
        }
    },
    /*
     * 判断是否是string
     */
     _isString: function(str) {
        return Object.prototype.toString.apply(str) === '[object String]';
     },
    /*
     * JS 动态添加css样式
     */
    _addStyleSheet: function(refWin, cssText, id){

        var self = this;
        if(self._isString(refWin)) {
            id = cssText;
            cssText = refWin;
            refWin = window;
        }
        refWin = $(refWin);
        var doc = document;
        var elem;

        if (id && (id = id.replace('#', ''))) {
            elem = $('#' + id, doc);
        }

        // 仅添加一次,不重复添加
        if (elem) {
            return;
        }
       //elem = $('<style></style>'); 不能这样创建 IE8有bug
        elem =  document.createElement("style");
        // 先添加到 DOM 树中,再给 cssText 赋值,否则 css hack 会失效
        $('head', doc).append(elem);

        if (elem.styleSheet) { // IE
            elem.styleSheet.cssText = cssText;
        } else { // W3C
            elem.appendChild(doc.createTextNode(cssText));
        }
    },
    /*
     * 销毁操作 释放内存
     */
    destory: function() {
        var self = this,
            _config = self.config,
            _cache = self.cache;
        _cache.ret  = [];
        _cache.currentIndex = 0;
        _cache.oldIndex = 0;
        _cache.inputArrs = [];
        _config.targetCls = null;
    }
 };
 // 初始化
 $(function(){
    var auto = new AutoComplete({
       // url: '/rocky/commonservice/user/find.json'
    });
 });

js实现搜索框关键字智能匹配代码 主要为大家分享了js实现搜索框关键字智能匹配代码,感兴趣的朋友可以参考一下 立即下载

相关推荐

JavaScript实现搜索框的自动完成功能(一)

在很多需要搜索的网站, 都会有一个自动完成的搜索框. 方便用户查找他们想要的搜索词. 帮助用户快速找到自己想要的结果.接下来通过本文给大家介绍JavaScript实现搜索框的自动完成功能(一),需要的朋友参考下吧

js实现搜索框智能搜索提示,类似百度搜索

js实现搜索框智能搜索提示,类似百度搜索

supuerlovepc的博客 2932

安卓ai自动化脚本 Yyds.Auto实现 示例 纯ai图像识别自动点击脚本

纯ai识别实现自动化脚本

专注安卓前沿科技 4780

JS代码实现-搜索框输入后-回车实现搜索

1、JS代码         function entersearch(){             var event = window.event || arguments.callee.caller.arguments[0];             if (event.keyCode == 13)             {                 search();

无敌大将军 3111

ComfyUI全自动换装工作流:从零到一的实战指南

本文提供了一份详细的ComfyUI全自动换装工作流实战指南。从环境配置、模型准备到核心工作流架构的逐步拆解,手把手教你搭建一条高效的AI换装流水线。文章深入解析了从输入、预处理、融合到输出的四步核心逻辑,并分享了关键参数调优与进阶技巧,旨在帮助电商从业者、内容创作者及AI爱好者轻松实现高质量、高效率的“一键换装”。

weixin_29198045的博客 896

【STM32CubeIDE入门】(一)工程创建&工程配置

​写在前面:如果是刚接触stm32cubeide的同学推荐与这一篇文章共同阅读,能够更加快速认识上手stm32cubeide。 1、打开stm32cubeide,选择好工作目录进入主界面后,点击创建工程。

涛涛子的博客 1万+

原生js实现input搜索框实时检索功能实现,支持选中或回车生成tag标签(超简单)

实现input搜索框实时检索的功能,支持回车或选中后生成tag标签,公司设计出功能需求后,在市场上没找到差不多类似的,只能手撸一个了。

Sreadfast的博客 1322

2.实体机安装TrueNAS 方法

访问不了可以使用以下连接:提取码:0927。

Unofficial_user的博客 7431

JavaScript 实现搜索框联想功能(autocomplete)

" + arr[i].substr(0, val.length) + "

其实计算机并没有漏洞,漏洞在于人的身上 1875

PaddleOCR 3.x 最新版使用教程(2025)——从安装到实战身份证识别,一步到位!

本文针对PaddleOCR 3.x大版本更新带来的参数变化和兼容性问题,提供从环境配置到实际应用的全流程解决方案。

qq_58607032的博客 9787

用deepseek对GPU服务器进行压力测试

利用 DeepSeek 模型对 GPU 服务器进行压力测试,核心思路是通过,验证 GPU 服务器在计算、显存、网络等维度的承载能力,同时观察稳定性与性能瓶颈。

weixin_42795092的博客 1610

用JavaScript写一个简易的自动搜索框

HTML 中需要注意的是,JavaScript 的引用的位置。JavaScript的位置引用不合适可能会导致代码报错,或者 JavaScript 获取到的内容为空。所以 JavaScript 一般引用在代码最下面。

好好吃饭,好好睡觉 1561

黑猫带你学eMMC协议第2篇:eMMC部分相关名词释义

1 前言 1.1 声明 本文依据eMMC JEDEC5.1、网络资料及个人工作经验整理而成,如有错误请留言。 本文结合eMMC JEDEC5.1协议手册查看效果更佳。 1.2 本文背景 本文关键词不包括emmc jedec5.1协议第3章节:《Terms and definitions》内容。关于emmc协议层的关键词,直接查阅spec相关章节即可,清晰明了,此处没必要再列出。 本文为本人工作学习中常听到或常用到关乎于emmc/flash的一些关键词合集,没有固定分类,不需要强行记忆,供查询使用。 1.

黑猫奥利奥的博客 7432

js php百度模糊搜索,JS仿百度搜索自动提示框匹配查询功能

/*** JS 模糊查询* @author tugenhua* @date 2013-11-19* @param 1.当前的input add targetCls* 2. 隐藏域里面统一增加同类名 叫 hiddenCls* 3. 在各个父级元素上 添加类名 parentCls*/function AutoComplete (options) {this.config = {targetCls...

weixin_34587189的博客 255

从零开始:手把手教你设计人形机器人锂电池供电系统

人形机器人要像人类一样“活起来”,必须有稳定的“能量血液”——供电系统。本文聚焦锂电池供电系统如何根据机器人功耗选择合适的锂电池参数(容量、电压、放电倍率);如何设计电池管理系统(BMS)保护电池安全;如何解决机器人运动时的“瞬时大电流”供电难题;如何通过硬件电路和代码实现供电系统的监测与控制。用“机器人小助手的能量危机”故事引入锂电池供电系统;拆解锂电池核心参数(容量、电压、放电倍率)和供电系统三大组件(电池组、BMS、电源转换模块);

AI天才研究院 1758

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

JQuery+ajax实现类似百度搜索自动匹配功能

引言    我们接触最多的、用的最多的搜索引擎就是百度了,可以说现在我们的生活如果离开像百度、谷歌这样的搜索引擎还是我们的生活没有了方向,我们在使用的时候都有一个体验就是我我们在输入关键紫的时候,他会自动给我们匹配很多的关键字,像下图所示:            这种非常人性化的功能对于我们在平常开发软件的时候是非常有必要借鉴的,所以在小编最近的项目中就需要用到这个功能给用户

Jack 架构师之路 1万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

JS实现自动提示框匹配查询

本文介绍一下仿百度搜索框,当对输入框键入文字时,自动弹出建议选项并匹配。 效果如下: OK,首先,建个输入框哈 1 <!DOCTYPE html> 2 <html> 3 <meta charset="utf-8"> 4 <head> 5 <title>自动搜索</title&...

ban2413的博客 210

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

模仿百度搜索自动匹配

效果图:模仿百度搜索,实现输入框自动匹配,思路如下(1)首先为输入框绑定keyup事件,当键盘按键弹起时触发(2)判断键盘按键:如果是回车键,则判断输入框内容是否为空,若为空,则提示“请输入搜索内容”,如果不为空,则直接进行搜索;如果是上下翻页键,判断匹配结果是否已经显示,如果已经显示,并且当前还能继续移动(比如,当前高亮显示的某个匹配结果已经是第一个了,肯定不能再向上移动了。。。。),则向上或者...

qq_24794717的博客 1240

仿百度词条搜索功能代码

baidu.html 无标题文档 function initBaidu(){ document.getElementById("div").style.border="none"; } function testAjax(str){ testXHR('baidu.php',"c="+encodeURI(str),m_xhr); } functio

liuhao_yu的专栏 1214

jquery 实现类似于百度自动匹配搜索

正如题目中提到的:jquery实现类似于百度自动匹配搜索,首先,我们看一下实现效果:                 实现这样的效果并不难,难的是这样的设计理念是不是我们作为软件开发的必备素质。         起初,我的需求是这样的:每一个注册我们高校云平台的学校用户,在输入自己学校全称的同时,要在下拉框中匹配出所有的带有该字样的所有学校名称,一方面核实该学校是否是已在教育部注册的高校,一

keep innocent 3434

JavaScript实现类似百度的智能搜索框

很多网站都提供智能搜索框这一功能,它能根据用户的输入自动提示出需要补全的数据项,方便了用户的查询操作。下面用JavaScript+jquery在前端层面实现了智能搜索框功能,代码如下: <!DOCTYPE html> <html lang="en"> <head> <title>智能搜索框</title> <meta...

whuhewei的博客 2391

input 仿百度下拉框

<input id="companyName" path="companyName" maxlength="50" class="form-control" autocomplete="off" placeholder="请至少输入两个字符进行查询" oninput="findCompany()"/> <div id="auto_div" style="position: ab...

Xiark2015的博客 956

可模糊查询输入框(仿百度搜索栏)

可模糊查询输入框(仿百度搜索),非插件、框架封装流。手写

紫菜中毒的博客 3万+

[转载]仿百度搜索提示框jQuery自动完成

转自:http://www.cnblogs.com/tangself/archive/2011/07/27/2118447.html<html> <head><title>AutoComplete-Sample</title> <style> #auto_div{ position:absolute; bo...

anduoji8601的博客 169

百度搜索提示java_使用Ajax模仿百度搜索框的自动提示功能实例

啊啊,熬夜了。今天学习了ajax给我的感觉就是,”哇塞“ajax好酷炫哦,(额。。。后端狗,接触到了大前端的魅力了),这么晚了还是直奔主题把。Let's go!百度搜索提示框,我想大家都很熟悉了把,是什么样子我也就不再赘述。直接看代码来我们写一个简陋的jsp页面 Look! 是这个样子的下面是代码:pageEncoding="UTF-8"%>Test Baiduwindow.onload=f...

weixin_30402009的博客 356
上一篇: 动态实现表单提交验证
下一篇: undefined与null的区别
java_zhaoyanli
博客等级 码龄12年 61粉丝 250原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值