开发者

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.

  1. Add a class to the textarea.
  2. On textarea focus remove the class.
  3. 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?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜