将字母添加到文本区域的末尾

Add the letters to the end in a textarea

即使用户试图将光标放在中间,我也想在文本区域中当前文字的末尾添加新输入的键盘输入。

试试这个对我有用的代码片段。 jsfiddle here

  $("#InputAtLast").keyup(function(e) {
    this.selectionStart = this.selectionEnd = this.value.length;
  });
  $("#InputAtLast").focus(function(e) {
    this.selectionStart = this.selectionEnd = this.value.length;
  });
  $("#InputAtLast").click(function(e) {
    this.selectionStart = this.selectionEnd = this.value.length;
  });

如需更多选项,请在此处 link Click here.

试试这个