How to set the cursor position at the end of a string in a text field using jQuery?
问题 I am using jQuery 1.6 and I have a text field for which I would like the cursor to be positioned at the end of the string\text after the field receives focus. Is there a trivial or easy to do this? At this time I am using the following code: $jQ('#css_id_value').focus(function(){ this.select(); }); $jQ('css_id_value').focus(); 回答1: $('#foo').focus(function() { if (this.setSelectionRange) { this.setSelectionRange(this.value.length, this.value.length); } else if (this.createTextRange) { // IE