开发者

jQuery TypeWatch - Extending for empty input?

I've created my own autocomplete using ajax and I want to be able to monitor the search input as the user types... I'm using TypeWatch right now and the only issue I see is that if the user has backspaced and the input is now empty, my search results sit there.

开发者_如何学编程

What would be the best way of extending the TypeWatch function (perhaps adding a second callback) so that when the input it empty, I can remove the search results div?


Try this:

In typeWatch.js, add a line to the checkElement() function:

  // Fire if text > options.captureLength AND text != saved txt OR if override AND text > options.captureLength, OR if the results are empty and there was a previous search
  if ((elTxt.length > options.captureLength && elTxt.toUpperCase() != timer.text)
  || (override && elTxt.length > options.captureLength)
  || (elTxt.length == 0 && timer.text)
  ) {
    timer.text = elTxt.toUpperCase();
    timer.cb(elTxt);
  }
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜