首页 新闻 赞助 找找看

twitter typeahead文本自动补全JS库的问题

0
悬赏园豆:100 [待解决问题]

各位大哥好,以下是twitter typeahead的一个实例,用于文本框自动补全,类型百度搜索框那种。
我希望的是input失去焦点再判断,input值必须完成等于列表的某一行,才会被保留,例如input的值是a,虽然数组包含a字符,但由于a不是数组的某一行,所以input还是要清空。这个功能其实另一个类似的插件是自带的,大家可以参考一下:http://www.lovewebgames.com/jsmodule/autosearch.html
麻烦高手帮忙改一下代码,实现这个功能,感谢。

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<link  rel="stylesheet">
<script src="https://cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://cdn.bootcss.com/typeahead.js/0.11.1/typeahead.bundle.min.js"></script>
</head>
  
<body>
<div class="example" id="the-basics">
  <div class="demo">
    <input class="typeahead" type="text">
  </div>
</div>
<script>
  var bestPictures = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    prefetch: 'http://twitter.github.io/typeahead.js/data/films/post_1960.json',
    remote: {
      url: 'http://twitter.github.io/typeahead.js/data/films/queries/%QUERY.json',
      wildcard: '%QUERY'
    }
  });
 
  $('#remote .typeahead').typeahead(null, {
    name: 'best-pictures',
    display: 'value',
    source: bestPictures
  });
      
    </script>
</body>
</html>

cqwcns的主页 cqwcns | 初学一级 | 园豆:54
提问于:2019-10-15 16:29
< >
分享
所有回答(1)
0
张朋举 | 园豆:1915 (小虾三级) | 2019-10-15 19:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册