jQuery Set Cursor Position in Text Area
问题 How do you set the cursor position in a text field using jQuery? I\'ve got a text field with content, and I want the users cursor to be positioned at a certain offset when they focus on the field. The code should look kind of like this: $(\'#input\').focus(function() { $(this).setCursorPosition(4); }); What would the implementation of that setCursorPosition function look like? If you had a text field with the content abcdefg, this call would result in the cursor being positioned as follows: