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);
}
};
精彩评论