<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<Meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>flexselect tests</title>
<link rel="stylesheet" href="flexselect.css" type="text/css" media="screen" />
<style>
input { width: 400px; }
label,input { display: block; }
label { font-weight: bold; }
input,.flexselect_dropdown li { font-size: 1em; }
small { color: #999; }
.flexselect_selected small { color: #ddd; }
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>
<script src="liquidMetal.js" type="text/javascript"></script>
<script src="jquery.flexselect.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("select.special-flexselect").flexselect({ hideDropdownOnEmptyInput: true });
$("select.flexselect").flexselect();
$("input:text:enabled:first").focus();
$("form").submit(function() {
alert($(this).serialize());
return false;
});
});
</script>
</head>
<body>
<form>
<label>Pick a Top 100 University or College in north America: <em>(Start typing...)</em></label>
<select class="special-flexselect" id="school" name="school" tabindex="1" data-placeholder="Start typing a school name...">
<option value=""></option>
<option value="1">Massachusetts</option>
<option value="2">Harvard University</option>
<option value="3">University</Option>
<option value="4">检验</option>
<option value="5">测试</option>

</select>

<form>
</body>
</html>

jquery.flexselect.js

/**
 * flexselect: a jQuery plugin,version: 0.5.2 (2013-01-21)
 * @requires jQuery v1.3 or later
 *
 * FlexSelect is a jQuery plugin that makes it easy to convert a select Box into
 * a Quicksilver-style,autocompleting,flex matching selection tool.
 *
 * For usage and examples,visit:
 * http://rmm5t.github.com/jquery-flexselect/
 *
 * Licensed under the MIT:
 * http://www.opensource.org/licenses/mit-license.PHP
 *
 * copyright (c) 2009-2012,Ryan McGeary (ryan -[at]- mcgeary [*dot*] org)
 */
(function($) {
  $.flexselect = function(select,options) { this.init(select,options); };

  $.extend($.flexselect.prototype,{
    settings: {
      allowMismatch: false,allowMismatchBlank: true,// If "true" a user can backspace such that the value is nothing (even if no blank value was provided in the original criteria)
      sortBy: 'score',// 'score' || 'name'
      preSelection: true,hideDropdownOnEmptyInput: false,selectedClass: "flexselect_selected",dropdownClass: "flexselect_dropdown",inputIdTransform:    function(id)   { return id + "_flexselect"; },inputNameTransform:  function(name) { return; },dropdownIdTransform: function(id)   { return id + "_flexselect_dropdown"; }
    },select: null,input: null,dropdown: null,dropdownList: null,cache: [],results: [],lastAbbreviation: null,abbreviationBeforeFocus: null,selectedindex: 0,picked: false,allowMouseMove: true,dropdownMouSEOver: false,// Workaround for poor IE behaviors

    init: function(select,options) {
      this.settings = $.extend({},this.settings,options);
      this.select = $(select);
      this.preloadCache();
      this.renderControls();
      this.wire();
    },preloadCache: function() {
      this.cache = this.select.children("option").map(function() {
        return { name: $.trim($(this).text()),value: $(this).val(),score: 0.0 };
      });
    },renderControls: function() {
      var selected = this.settings.preSelection ? this.select.children("option:selected") : null;

      this.input = $("<input type='text' autocomplete='off' />").attr({
        id: this.settings.inputIdTransform(this.select.attr("id")),name: this.settings.inputNameTransform(this.select.attr("name")),accesskey: this.select.attr("accesskey"),tabindex: this.select.attr("tabindex"),style: this.select.attr("style"),placeholder: this.select.attr("data-placeholder")
      }).addClass(this.select.attr("class")).val($.trim(selected ? selected.text():  '')).css({
        visibility: 'visible'
      });

      this.dropdown = $("<div></div>").attr({
        id: this.settings.dropdownIdTransform(this.select.attr("id"))
      }).addClass(this.settings.dropdownClass);
      this.dropdownList = $("<ul></ul>");
      this.dropdown.append(this.dropdownList);

      this.select.after(this.input).hide();
      $("body").append(this.dropdown);
    },wire: function() {
      var self = this;

      this.input.click(function() {
        self.lastAbbreviation = null;
        self.focus();
      });

      this.input.mouseup(function(event) {
        // This is so Safari selection actually occurs.
        event.preventDefault();
      });

      this.input.focus(function() {
        self.abbreviationBeforeFocus = self.input.val();
        self.input.select();
        if (!self.picked) self.filterResults();
      });

      this.input.blur(function() {
        if (!self.dropdownMouSEOver) {
          self.hide();
          if (self.settings.allowMismatchBlank && $.trim($(this).val()) == '')
            self.setValue('');
          if (!self.settings.allowMismatch && !self.picked)
            self.reset();
        }
        if (self.settings.hideDropdownOnEmptyInput)
          self.dropdownList.show();
      });

      this.dropdownList.mouSEOver(function(event) {
        if (!self.allowMouseMove) {
          self.allowMouseMove = true;
          return;
        }

        if (event.target.tagName == "LI") {
          var rows = self.dropdown.find("li");
          self.markSelected(rows.index($(event.target)));
        }
      });
      this.dropdownList.mouseleave(function() {
        self.markSelected(-1);
      });
      this.dropdownList.mouseup(function(event) {
        self.pickSelected();
        self.focusAndHide();
      });
      this.dropdown.mouSEOver(function(event) {
        self.dropdownMouSEOver = true;
      });
      this.dropdown.mouseleave(function(event) {
        self.dropdownMouSEOver = false;
      });
      this.dropdown.mousedown(function(event) {
        event.preventDefault();
      });

      this.input.keyup(function(event) {
        switch (event.keyCode) {
          case 13: // return
            event.preventDefault();
            self.pickSelected();
            self.focusAndHide();
            break;
          case 27: // esc
            event.preventDefault();
            self.reset();
            self.focusAndHide();
            break;
          default:
            self.filterResults();
            break;
        }
        if (self.settings.hideDropdownOnEmptyInput){
          if(self.input.val() == "")
            self.dropdownList.hide();
          else
            self.dropdownList.show();
        }
      });

      this.input.keydown(function(event) {
        switch (event.keyCode) {
          case 9:  // tab
            self.pickSelected();
            self.hide();
            break;
          case 33: // pgup
            event.preventDefault();
            self.markFirst();
            break;
          case 34: // pgedown
            event.preventDefault();
            self.markLast();
            break;
          case 38: // up
            event.preventDefault();
            self.moveSelected(-1);
            break;
          case 40: // down
            event.preventDefault();
            self.moveSelected(1);
            break;
          case 13: // return
          case 27: // esc
            event.preventDefault();
            event.stopPropagation();
            break;
        }
      });

      var input = this.input;
      this.select.change(function () {
        input.val($.trim($(this).children('option:selected').text()));
      });
    },filterResults: function() {
      var abbreviation = this.input.val();
      if (abbreviation == this.lastAbbreviation) return;

      var results = [];
      $.each(this.cache,function() {
        this.score = LiquidMetal.score(this.name,abbreviation);
        if (this.score > 0.0) results.push(this);
      });
      this.results = results;

      if (this.settings.sortBy == 'score')
        this.sortResultsByscore();
      else if (this.settings.sortBy == 'name')
        this.sortResultsByName();

      this.renderDropdown();
      this.markFirst();
      this.lastAbbreviation = abbreviation;
      this.picked = false;
      this.allowMouseMove = false;
    },sortResultsByscore: function() {
      this.results.sort(function(a,b) { return b.score - a.score; });
    },sortResultsByName: function() {
      this.results.sort(function(a,b) { return a.name < b.name ? -1 : (a.name > b.name ? 1 : 0); });
    },renderDropdown: function() {
      var dropdownBorderWidth = this.dropdown.outerWidth() - this.dropdown.innerWidth();
      var inputOffset = this.input.offset();
      this.dropdown.css({
        width: (this.input.outerWidth() - dropdownBorderWidth) + "px",top: (inputOffset.top + this.input.outerHeight()) + "px",left: inputOffset.left + "px",maxHeight: ''
      });

      var html = '';
      $.each(this.results,function() {
        //html += '<li>' + this.name + ' <small>[' + Math.round(this.score*100)/100 + ']</small></li>';
        html += '<li>' + this.name + '</li>';
      });
      this.dropdownList.html(html);
      this.adjustMaxHeight();
      this.dropdown.show();
    },adjustMaxHeight: function() {
      var maxTop = $(window).height() + $(window).scrollTop() - this.dropdown.outerHeight();
      var top = parseInt(this.dropdown.css('top'),10);
      this.dropdown.css('max-height',top > maxTop ? (Math.max(0,maxTop - top + this.dropdown.innerHeight()) + 'px') : '');
    },markSelected: function(n) {
      if (n < 0 || n >= this.results.length) return;

      var rows = this.dropdown.find("li");
      rows.removeClass(this.settings.selectedClass);
      this.selectedindex = n;

      var row = $(rows[n]).addClass(this.settings.selectedClass);
      var top = row.position().top;
      var delta = top + row.outerHeight() - this.dropdown.height();
      if (delta > 0) {
        this.allowMouseMove = false;
        this.dropdown.scrollTop(this.dropdown.scrollTop() + delta);
      } else if (top < 0) {
        this.allowMouseMove = false;
        this.dropdown.scrollTop(Math.max(0,this.dropdown.scrollTop() + top));
      }
    },pickSelected: function() {
      var selected = this.results[this.selectedindex];
      if (selected) {
        this.input.val(selected.name);
        this.setValue(selected.value);
        this.picked = true;
      } else if (this.settings.allowMismatch) {
        this.setValue.val("");
      } else {
        this.reset();
      }
    },setValue: function(val) {
      if (this.select.val() === val) return;
      this.select.val(val).change();
    },hide: function() {
      this.dropdown.hide();
      this.lastAbbreviation = null;
    },moveSelected: function(n) { this.markSelected(this.selectedindex+n); },markFirst:    function()  { this.markSelected(0); },markLast:     function()  { this.markSelected(this.results.length - 1); },reset:        function()  { this.input.val(this.abbreviationBeforeFocus); },focus:        function()  { this.input.focus(); },focusAndHide: function()  { this.focus(); this.hide(); }
  });

  $.fn.flexselect = function(options) {
    this.each(function() {
      if (this.tagName == "SELECT") new $.flexselect(this,options);
    });
    return this;
  };
})(jQuery);


liquidMetal.js

/**
 * LiquidMetal,version: 1.2.1 (2012-04-21)
 *
 * A mimetic poly-alloy of Quicksilver's scoring algorithm,essentially
 * LiquidMetal.
 *
 * For usage and examples,visit:
 * http://github.com/rmm5t/liquidMetal
 *
 * Licensed under the MIT:
 * http://www.opensource.org/licenses/mit-license.PHP
 *
 * copyright (c) 2009-2012,Ryan McGeary (ryan -[at]- mcgeary [*dot*] org)
 */
var LiquidMetal = (function() {
  var score_NO_MATCH = 0.0;
  var score_MATCH = 1.0;
  var score_TRAILING = 0.8;
  var score_TRAILING_BUT_STARTED = 0.9;
  var score_BUFFER = 0.85;
  var WORD_SEParaTORS = " \t_-";

  return {
    lastscore: null,lastscoreArray: null,score: function(string,abbrev) {
      // short circuits
      if (abbrev.length === 0) return score_TRAILING;
      if (abbrev.length > string.length) return score_NO_MATCH;

      // match & score all
      var allscores = [];
      var search = string.toLowerCase();
      abbrev = abbrev.toLowerCase();
      this._scoreAll(string,search,abbrev,-1,[],allscores);

      // complete miss
      if (allscores.length == 0) return 0;

      // sum per-character scores into overall scores,// selecting the maximum score
      var maxscore = 0.0,maxArray = [];
      for (var i = 0; i < allscores.length; i++) {
        var scores = allscores[i];
        var scoreSum = 0.0;
        for (var j = 0; j < string.length; j++) { scoreSum += scores[j]; }
        if (scoreSum > maxscore) {
          maxscore = scoreSum;
          maxArray = scores;
        }
      }

      // normalize max score by string length
      // s. t. the perfect match score = 1
      maxscore /= string.length;

      // record maximum score & score array,return
      this.lastscore = maxscore;
      this.lastscoreArray = maxArray;
      return maxscore;
    },_scoreAll: function(string,searchIndex,abbrIndex,scores,allscores) {
      // save completed match scores at end of search
      if (abbrIndex == abbrev.length) {
        // add trailing score for the remainder of the match
        var started = (search.charat(0) == abbrev.charat(0));
        var trailscore = started ? score_TRAILING_BUT_STARTED : score_TRAILING;
        fillArray(scores,trailscore,scores.length,string.length);
        // save score clone (since reference is persisted in scores)
        allscores.push(scores.slice(0));
        return;
      }

      // consume current char to match
      var c = abbrev.charat(abbrIndex);
      abbrIndex++;

      // cancel match if a character is missing
      var index = search.indexOf(c,searchIndex);
      if (index == -1) return;

      // match all instances of the abbreviaton char
      var scoreIndex = searchIndex; // score section to update
      while ((index = search.indexOf(c,searchIndex+1)) != -1) {
        // score this match according to context
        if (isNewWord(string,index)) {
          scores[index-1] = 1;
          fillArray(scores,score_BUFFER,scoreIndex+1,index-1);
        }
        else if (isUpperCase(string,index)) {
          fillArray(scores,index);
        }
        else {
          fillArray(scores,score_NO_MATCH,index);
        }
        scores[index] = score_MATCH;

        // consume matched string and continue search
        searchIndex = index;
        this._scoreAll(string,allscores);
      }
    }
  };

  function isUpperCase(string,index) {
    var c = string.charat(index);
    return ("A" <= c && c <= "Z");
  }

   function isNewWord(string,index) {
    var c = string.charat(index-1);
    return (WORD_SEParaTORS.indexOf(c) != -1);
  }

  function fillArray(array,value,from,to) {
    for (var i = from; i < to; i++) { array[i] = value; }
    return array;
  }
})();



http://download.csdn.net/detail/maxuyang1987/5833809

ajax select 搜索提出的更多相关文章

  1. HTML5、Select下拉框右边加图标的实现代码(增进用户体验)

    这篇文章主要介绍了HTML5、Select下拉框右边加图标的实现代码,深度美化页面增进用户体验效果,需要的朋友可以参考下

  2. 在Sierra上,Brew安装错误单独使用Xcode是不够的

    我正在尝试使用HomeBrewv1.3.8在运行xCodev9.1的MacOSXSerrav10.12.6上安装软件包.安装和错误是然后我运行命令表示软件更新服务器无法使用命令行工具包.我进入xCode,它表明安装了命令行工具.任何帮助将非常感激.西奥解决方法我去了AppleDeveloper网站并直接下载了命令行工具dmg.首先需要设置Apple帐户.命令行工具可在以下位置找到–https://

  3. iOS 10 Safari问题在DOM中不再包含元素

    使用此链接,您可以重现该错误.https://jsfiddle.net/pw7e2j3q/如果您点击元素并从dom中删除它,然后单击链接测试.你应该看到旧的元素弹出选择.是否有一些黑客来解决这个问题?解决方法我能够重现这个问题.问题是,每当您尝试删除其更改事件上的选择框时,iOS10都无法正确解除对选择框的绑定.要解决此问题,您需要将代码更改事件代码放在具有一些超时

  4. iOS Chrome上的HTML SELECT不显示“完成”选项

    我们在iOS上的Chrome中使用UI呈现时遇到问题,特别是HTMLSELECTDropDown元素.例:使用Safari,当您点击SELECT时,屏幕底部会打开一个微调器–您可以点击完成以选择您的选择并返回到表单.但是,当您在iOS上的Chrome中加载完全相同的页面时,不会显示“完成”.用户必须选择他们的选择,然后点击UI上的其他位置返回到表单.非常不直观,用户感觉好像SELECT没有用.有人有解决方案吗?

  5. 安装命令行工具Xcode 5

    我已经尝试过并尝试过但我仍然无法解决问题.我正在尝试安装PebbleSDK1.12并安装Xcode5的命令行工具.每次我在终端尝试xcode-select–install时,我都会收到“无法安装软件,因为它目前在软件更新服务器中不可用”我试图重新安装Xcode,但是没有用.当我进入Xcode-preferences-downloads时,没有命令行工具的部分.我也试过从开发者网站安装它们但无济于事.下载看起来正确,然后我去Xcode看到首选项,并没有列出命令行工具.你们都能提出什么建议吗?

  6. ios – xcodebuild相当于Xcode的“产品&gt;构建&gt;测试”

    我正在尝试编写一个脚本,将iOS应用程序提交给AppThwack(一个“真正的设备”UI测试服务).他们的指导是使用XcodeGUI,并使用BuildFor>Xcode产品菜单中的测试选项.这是有效的,但我无法将其转换为xcodebuild等效项.更一般地说,我们如何确定Xcode传递给xcodebuild的什么参数(假设它使用该工具).解决方法现在可以从Xcode8开始(在写作时在beta版).

  7. xcode – 在REPL中创建目标Swift AST上下文时出错((null))

    在这里,我已经看到有关这个错误的几个的问题,但是没有一个提出的解决方案适用于我.这是我得到的这可能是也可能没有发生在我发出一些我不记得的命令之后.奇怪的是,如果我卸载Xcode,REPL开始正常工作.但是,如果我重新安装Xcode,错误就会回来.我在Xcode7.2.1,顺便说一句.思考?

  8. IOS设备问题与HTML表单输入(type = text)

    所以我有一个HTML登录表单与两个字段:电子邮件和密码.这些可以在除iOS设备之外的任何设备的浏览器上轻松填充.在IOS领域几乎不能关注焦点,一旦焦点,键盘弹出,我开始打字,但实际上没有填充.我已经尝试过Chrome和safari,仍然得到相同的结果.字段保持黑色.Bellow是我的格式如何格式化:请帮助!

  9. 我在哪里可以获得XCode的10.6 SDK

    我有SNowLeopard的测试版,我从DVD上安装了XCode,但它只安装了10.5和10.4SDK.我需要针对10.6构建以验证Apple的错误.解决方法ADCMemberSite.登录并选择下载.如果您是Premier或Select会员,那应该是您可以找到它的地方.如果您不是Premier或Select会员,您将看不到它.

  10. 应用程序关闭时的iOS任务

    我正在构建一个应用程序,通过ajax将文件上传到服务器.问题是用户很可能有时不会有互联网连接,并且客户希望在用户重新连接时安排ajax调用.这可能是用户在离线时安排文件上传并关闭应用程序.应用程序关闭时可以进行ajax调用吗?

随机推荐

  1. xe-ajax-mock 前端虚拟服务

    最新版本见Github,点击查看历史版本基于XEAjax扩展的Mock虚拟服务插件;对于前后端分离的开发模式,ajax+mock使前端不再依赖后端接口开发效率更高。CDN使用script方式安装,XEAjaxMock会定义为全局变量生产环境请使用xe-ajax-mock.min.js,更小的压缩版本,可以带来更快的速度体验。

  2. vue 使用 xe-ajax

    安装完成后自动挂载在vue实例this.$ajaxCDN安装使用script方式安装,VXEAjax会定义为全局变量生产环境请使用vxe-ajax.min.js,更小的压缩版本,可以带来更快的速度体验。cdnjs获取最新版本点击浏览已发布的所有npm包源码unpkg获取最新版本点击浏览已发布的所有npm包源码AMD安装require.js安装示例ES6Module安装通过Vue.use()来全局安装示例./Home.vue

  3. AJAX POST数据中文乱码解决

    前端使用encodeURI进行编码后台java.net.URLDecoder进行解码编解码工具

  4. Koa2框架利用CORS完成跨域ajax请求

    实现跨域ajax请求的方式有很多,其中一个是利用CORS,而这个方法关键是在服务器端进行配置。本文仅对能够完成正常跨域ajax响应的,最基本的配置进行说明。这样OPTIONS请求就能够通过了。至此为止,相当于仅仅完成了预检,还没发送真正的请求呢。

  5. form提交时,ajax上传文件并更新到&lt;input&gt;中的value字段

  6. ajax的cache作用

    filePath="+escape;},error:{alert;}});解决方案:1.加cache:false2.url加随机数正常代码:网上高人解读:cache的作用就是第一次请求完毕之后,如果再次去请求,可以直接从缓存里面读取而不是再到服务器端读取。

  7. 浅谈ajax上传文件属性contentType = false

    默认值为contentType="application/x-www-form-urlencoded".在默认情况下,内容编码类型满足大多数情况。在这里,我们主要谈谈contentType=false.在使用ajax上传文件时:在其中先封装了一个formData对象,然后使用post方法将文件传给服务器。说到这,我们发现在JQueryajax()方法中我们使contentType=false,这不是冲突了吗?这就是因为当我们在form标签中设置了enctype=“multipart/form-data”,

  8. 909422229_ajaxFileUpload上传文件

    ajaxFileUpload.js很多同名的,因为做出来一个很容易。我上github搜AjaxFileUpload出来很多类似js。ajaxFileUpload是一个异步上传文件的jQuery插件传一个不知道什么版本的上来,以后不用到处找了。语法:$.ajaxFileUploadoptions参数说明:1、url上传处理程序地址。2,fileElementId需要上传的文件域的ID,即的ID。3,secureuri是否启用安全提交,默认为false。4,dataType服务器返回的数据类型。6,error

  9. AJAX-Cache:一款好用的Ajax缓存插件

    原文链接AJAX-Cache是什么Ajax是前端开发必不可少的数据获取手段,在频繁的异步请求业务中,我们往往需要利用“缓存”提升界面响应速度,减少网络资源占用。AJAX-Cache是一款jQuery缓存插件,可以为$.ajax()方法扩展缓存功能。

  10. jsf – Ajax update/render在已渲染属性的组件上不起作用

    我试图ajax更新一个有条件渲染的组件。我可以确保#{user}实际上是可用的。这是怎么引起的,我该如何解决呢?必须始终在ajax可以重新呈现之前呈现组件。Ajax正在使用JavaScriptdocument.getElementById()来查找需要更新的组件。但是如果JSF没有将组件放在第一位,那么JavaScript找不到要更新的内容。解决方案是简单地引用总是渲染的父组件。

返回
顶部