Input not scrolling to the far right like it should

I have an input field where i append data at the cursor position.

after that, i set the selectionStart to the end of the field.

BUT, whenever i add something to the input (by button clicks), i only see the left part of it (until it reaches the right edge). everything more is there (i can select it with the mouse and scroll), but it doesn't automatically show the right edge.

how can i do that? i want to add something to the input and jump right to the end of the string.

  // add 2 digit number
  $('button#2digit').on('click', function add2digit() {
    addNumberToInput(10, 99);
  });

  function addNumberToInput(min, max) {
    var problemInput = $('input#testProblem');
    if (lastCharIsOperation() || problemInput.val().trim() < 1) {  // if last char is an operation or first in string, just append the number
      addAtCursor(randomNonPrime(min, max));
    } else {
      addAtCursor('+' + randomNonPrime(min, max));
    }
  }



  function addAtCursor(toAdd) {
    var problemInput = $('input#testProblem');

    var oldText = problemInput.val();
    var cursor = problemInput[0].selectionStart;

    var pre = oldText.substring(0,cursor);
    var post = oldText.substring(cursor, oldText.length);

    //insert at cursor
    problemInput.val(pre + toAdd + post);

    //put cursor to end
    problemInput[0].selectionStart = problemInput.val().length;
  }

(it even skips back to the left on blur, i couldn't make a picture with the windows snipping tool, because i had to click it first)

np在这里

这里到达最后


From Set mouse focus and move cursor to end of input using jQuery.

var problemInput = $('input#testProblem');
problemInput.focus();
var t=problemInput.val();
problemInput.val('');
problemInput.val(t);

Here is the start of a full solution: https://jsfiddle.net/michaelgentry/vwm159pt/


这仍然会导致滚动在模糊状态下跳回到左侧,但不会执行您所问的内容:

 var elem = document.getElementById('myInput');
 elem.focus();
 elem.scrollLeft = elem.scrollWidth;
链接地址: http://www.djcxy.com/p/68458.html

上一篇: 游标位置异常位于Chrome中输入值的末尾

下一篇: 输入不像它应该滚动到最右边