js输入框自动完成代码

      
horsey(document.querySelector('input'), {
  suggestions: ['banana', 'apple', 'orange']
});
      
    
Being lazy...
      
horsey(document.querySelector('input'), {
  suggestions: function (done) {
    setTimeout(function () {
      done(['banana', 'apple', 'orange']);
    }, 2000);
  }
});
      
    
      
horsey(document.querySelector('input'), {
  suggestions: [
    { value: 'banana', text: 'Bananas from Amazon Rainforest' },
    { value: 'apple', text: 'Red apples from New Zealand' },
    { value: 'orange', text: 'Oranges from Moscow' },
    { value: 'lemon', text: 'Juicy lemons from Amalfitan Coast' }
  ]
});
      
    

适用浏览器:360、FireFox、Chrome、Safari、Opera、傲游、搜狗、世界之窗. 不支持IE8及以下浏览器。

来源:懒人素材