问题
So here's what I'm working on:
http://jsfiddle.net/hn8EY/
$("input").mouseup(function(){
this.selectionStart = this.value.length;
this.selectionEnd = this.value.length;
});
This is working fine for physically setting the position of the cursor, but I also want it to be where the viewpoint of the user jumps to that point, so that the current position of the cursor is actually shown. I don't know if there is any solution to this.
回答1:
Try setting the scrollLeft:
$("input").mouseup(function(){
var valLength = this.value.length;
this.setSelectionRange(valLength , valLength ); //or this.selectionStart = this.value.length; this.selectionEnd = this.value.length;
//or just use this.selectionStart = this.value.length;
this.scrollLeft = this.scrollWidth;
});
Fiddle
来源:https://stackoverflow.com/questions/20252449/jquery-focus-textbox-and-go-to-end-but-also-set-the-position-of-the-cursor-so-u