我需要它,以便在按下按钮时,光标将:
1) 定位句尾 2) 将光标从句尾“x”向后移动很多个空格(x为变量);
这是一个小提琴 -----> jsFiddle <-----
HTML
<span>From the end, move the cursor back this many spaces: </span>
<input type='text' id='num' size='5'/>
<button>Submit</button>
<br/><br/>
<textarea>The cursor will move in here</textarea>
jQuery
$(document).ready(function() {
$('button').click(function() {
var myval = parseInt($('#num').val()); //the number of spaces to move back
//code to move cursor back - starting from the END OF THE STATEMENT
});
});