zoukankan      html  css  js  c++  java
  • 自动搜索

    自动搜索中用的插件是jqury中ui插件:

    先引入:jquery-ui-1.9.0.custom.min.css和jquery-ui-1.9.0.custom.min.js

    然后js中的代码调用是:

     1 var list = [];
     2     var $seachText = $('#search-node-input');
     3     $seachText.bind("keydown",function (event) {
     4         if (event.keyCode === $.ui.keyCode.TAB && $(this).data("autocomplete").menu.active) {
     5         }
     6     }).bind("focus", function(event){
     7         if (event.keyCode === $.ui.keyCode.TAB && $(this).data("autocomplete").menu.active) {
     8         }
     9     }).autocomplete({
    10         minLength:1,
    11         source:function (request, response) {
    12             $.get("{:U('admin/Content/getAddLocation')}", {name: request.term}, function(data){
    13                 if (data.code >= 0) {
    14                     list = data.data;
    15                     if (list.length) {
    16                         if (type_value != '1') {
    17                             $('.location_name_tip').html('');
    18                         }
    19 
    20                         response($.map(list, function (item) {
    21                             var val = item.location_name ? item.location_name : item.location_bame;
    22                             return {
    23                                 label:'['+item.area_name+']'+val,
    24                                 value:val,
    25                                 id:item.location_id,
    26                                 hot_num:item.location_hot,
    27                                 recommend_num:1,
    28                                 hit_num:item.location_hot,
    29                                 show_num:item.location_hot,
    30                                 imgInfo:item.attach_arr_id,
    31                                 attach_id:item.attach_id,
    32                                 to_url:item.detail_url
    33                             }
    34                         }));
    35                     } else {
    36                         fillValue();
    37                         response(['搜索不到相关信息']);
    38 
    39                         if (type_value != '1') {
    40                             $('.location_name_tip').html('搜索不到相关信息');
    41                             $('.location_name_tip').css({color:'#f00'});
    42                         }
    43                     }
    44                 }
    45                 return false;
    46             }, 'json');
    47         },
    48         select:function (event, ui) {
    49             $('#fid').val(ui.item.id);
    50             fillValue(ui.item);
    51         }
    52     }).css({'position':'relative','z-index':99999});
     1 function fillValue(obj) {
     2         var prefix_div;
     3         if (undefined != obj && obj) {
     4             if (type_value == 1) {
     5                 prefix_div = 'activity_';
     6             } else {
     7                 prefix_div = 'location_';
     8                 $('.div_location input[name='+prefix_div+'hot_num]').val(obj.hot_num);
     9                 $('.div_location input[name='+prefix_div+'recommend_num]').val(obj.recommend_num);
    10                 $('.div_location input[name='+prefix_div+'hit_num]').val(obj.hit_num);
    11                 $('.div_location input[name='+prefix_div+'show_num]').val(obj.show_num);
    12 
    13                 var imgStr = '';
    14 
    15                 for (var imgK in obj.imgInfo) {
    16                     imgStr += "<li style='float:left;' onclick='selectImg("+imgK+")'>";
    17                     imgStr += "<img src='"+obj.imgInfo[imgK].img+"' width='183px' height='130px' />";
    18                     imgStr += "<input type='radio' />"+obj.imgInfo[imgK].img_width+"x"+obj.imgInfo[imgK].img_height;
    19                     imgStr += "<input type='hidden' value='"+obj.imgInfo[imgK].a_img+"' />";
    20                     imgStr += "</li>";
    21                 }
    22 
    23                 if (imgStr) {
    24                     $('.location_imgShow_ul').html(imgStr);
    25                 }
    26 
    27                 $('.div_location input[name='+prefix_div+'to_url]').val(obj.to_url);
    28             }
    29         } else {
    30             $('#fid').val('');
    31             if (type_value == 1) {
    32                 prefix_div = 'activity_';
    33             } else {
    34                 prefix_div = 'location_';
    35                 $('.div_location input[name='+prefix_div+'hot_num]').val('');
    36                 $('.div_location input[name='+prefix_div+'recommend_num]').val('');
    37                 $('.div_location input[name='+prefix_div+'hit_num]').val('');
    38                 $('.div_location input[name='+prefix_div+'show_num]').val('');
    39                 $('.location_imgShow_ul').html('');
    40                 $('.div_location input[name='+prefix_div+'to_url]').val('');
    41             }
    42         }
    43     }
  • 相关阅读:
    spring boot banner设置关闭以及关闭特定的自动配置
    spring boot 初始及快速搭建
    spring scheduling 计划任务
    idea database 导入实体带注解
    idea mapper下的方法找不到 Invalid bound statement (not found)
    spring jwt token 认证
    spring event 事件
    FrontEnd-Basis-6th
    FrontEnd-Basis-5th
    FrontEnd-Basis-4th
  • 原文地址:https://www.cnblogs.com/xingmeng/p/3412791.html
Copyright © 2011-2022 走看看