jQuery event when hash tag (or any character) is typed!
I have a textarea field on my website and I'd like to use jQuery to trigger an event when a user types the hash tag. Similar to the trend of websites like Facebook and Twitter who allow you to query a database for friends as you type after you type a hash tag or use the '@' symbol.
Would anyone be able to provide a plugin or example of how I could get started in the right direction with this? I've looked at the autocomplete plugin, which works great for querying the database, but what if I wanted to do something else, like pop 开发者_StackOverflow中文版up a div, etc? I'm basically looking for a way to trigger an even when the hash tag is typed and close the event when a user keeps typing?
Thanks for any help!
You could take a look at the keydown, keyup or keypress events (depending on your use case), and then check what character was last typed in the textarea in the handler. If the character is # - do a specific thing. Take a look at the examples on those documentation pages, and event.keyCode
.
How about: http://www.reynoldsftw.com/2009/01/jquery-acting-on-specific-key-events/
or a Javascript jQuery plugin for hooking keyboard events: http://code.google.com/p/js-hotkeys/
精彩评论