jQuery自动完成功能:matchContains不起作用 [英] jQuery autocomplete: matchContains not working

查看:312
本文介绍了jQuery自动完成功能:matchContains不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有jQuery和自动完成插件设置.自动完成功能可以正常工作,我设置的各种选项(例如宽度和查找效果)都可以.但是不起作用的一件事是matchContains选项.根据文档无论比较结果是否出现在内部(即"ba"是否匹配" foo bar)搜索结果.仅在使用缓存时才重要.请勿与自动填充功能混合使用."但这不是在搜索结果中查找.例如,"ba"将找不到"foo bar".

I have jQuery and the autocomplete plugin setup. Autocomplete works fine and various options I set like width and lookup work okay. But the one thing that does not work is the matchContains option. According to the doc "Whether or not the comparison looks inside (i.e. does "ba" match "foo bar") the search results. Important only if you use caching. Don't mix with autofill." But it is not looking inside the search results. For example, "ba" will not find "foo bar".

<script type="text/javascript" src="styles/prosilver/template/jquery.js"></script>
<script type="text/javascript" src="styles/prosilver/template/jquery.autocomplete.js"></script>


<script type="text/javascript">
// <![CDATA[

/* Zeno */
function translatestyle(text)
{
    var val = document.getElementById('query').value;
    var lang = '{S_USER_LANG}'.substring(0,2);
    var list = "{TRANS_LIST}";
    var arr = list.match(val);
    if ( arr == null )
    {
      alert('That is not a valid translation term.');
    }
    else
    {
      insert_text('[translate='+lang+']'+val+'[/translate]');
      document.forms[form_name].elements[text_name].focus();
    }
}


  var a2;

  jQuery(function() {

    var onAutocompleteSelect = function(value, data) {
      $('#selection').html('<img src="\/global\/flags\/small\/' + data + '.png" alt="" \/> ' + value);
      alert(data);
    }

    var options = {
      serviceUrl: '/projects/autocomplete/service/autocomplete.ashx',
      matchContains: true,
      width: 300,
      delimiter: /(,|;)\s*/,
      onSelect: onAutocompleteSelect,
      deferRequestBy: 0, //miliseconds
    };

    a2 = $('#query').autocomplete({
      matchContains: true,
      width: 300,
      delimiter: /(,|;)\s*/,
      lookup: "{TRANS_LIST}".split(',')
    });


    $('#navigation a').each(function() {
      $(this).click(function(e) {
        var element = $(this).attr('href');
        $('html').animate({ scrollTop: $(element).offset().top }, 300, null, function() { document.location = element; });
        e.preventDefault();
      });
    });

  });

推荐答案

我对该特定插件不熟悉,但是您可能想尝试切换到JQuery UI

I'm not familiar with that particular plugin, but you may want to try switching to the JQuery UI Autocomplete library. It's quite good, and does search inside the way you want.

这篇关于jQuery自动完成功能:matchContains不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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