JQuery A-Tools inserts at the end of a textarea when it doesn't have focus
I'm trying to use A-Tools to insert something at the caret position in a TEXTAREA. However, when the TEXTAREA doesn't have focus, the stuff gets thrown at the end (I'd like it to be at the beginning). However, I don't seem to be able to figure out when that focus开发者_如何转开发 isn't there to insert at the beginning, as the caret position returned when it's not focused varies widely.
Is there a way to do this?/
jQuery does not have a check for focus.
- Add a class to the textarea.
- On textarea focus remove the class.
- Before your function runs check if the textarea has the class. If it does that means it does not have focus. So if the class is on the textarea first run .focus(), then remove the class from the textarea.
Actually while writing this I though of a simpler solution, why don't you just always run .focus() on the textarea before you run the function?
精彩评论