开发者

jQuery TypeWatch - Extending for empty input?

开发者 https://www.devze.com 2023-01-20 07:42 出处:网络
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 back

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

精彩评论

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