jQuery用户界面自动完成:只允许从选择的建议列表价值 [英] jQuery UI AutoComplete: Only allow selected valued from suggested list

查看:197
本文介绍了jQuery用户界面自动完成:只允许从选择的建议列表价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在执行 jQuery UI的自动完成,并想知道是否有什么办法只允许从选择建议返回,而不是允许任何价值,结果被输入到文本框中。

I am implementing jQuery UI Autocomplete and am wondering if there is any way to only allow a selection from the suggested results that are returned as opposed to allowing any value to be input into the text box.

我用这一个标签系统很像在这个网站中使用的,所以我只希望允许用户从pre-填充的列表返回到自动完成插件选择标签。

I am using this for a tagging system much like the one used on this site, so I only want to allow users to select tags from a pre-populated list returned to the autocomplete plugin.

推荐答案

旧版本有,但已被删除。这里是如何做到这一点这里的一个例子:

The old version had it but has since been removed. There is an example on how to do this here:

<一个href="http://jqueryui.com/demos/autocomplete/#combobox">http://jqueryui.com/demos/autocomplete/#combobox

看的来源中。这是做的部分:

look in the source. This is the section that does that:

change: function( event, ui ) {
  if ( !ui.item ) {
    var matcher = new RegExp("^" + $.ui.autocomplete.escapeRegex($(this).val()) + "$", "i" ), valid = false;

    select.children("option").each(function() {
      if ($(this).text().match(matcher)) {
        this.selected = valid = true;
        return false;
      }
    });

    if (!valid) {
      // remove invalid value, as it didn't match anything
      $(this).val("");
      select.val("");
      input.data("autocomplete").term = "";
      return false;
    }
  }
}

这篇关于jQuery用户界面自动完成:只允许从选择的建议列表价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆