簡體   English   中英

將焦點設置為textarea的結尾

[英]Setting focus to the end of a textarea

editor.focus();

在Chrome中設置焦點很好。 但在Firefox中,重點是在線上開始。 我希望它設置在行尾。 我試過這個:

moveCaretToEnd(ed);

function moveCaretToEnd(el) {
    if (typeof el.selectionStart == "number") {
      el.selectionStart = el.selectionEnd = el.value.length;
    } else if (typeof el.createTextRange != "undefined") {
      el.focus();
      var range = el.createTextRange();
      range.collapse(false);
      range.select();
    }
}

而愚蠢的FF再也不起作用了。 焦點消失了。

我使用以下hafox for firefox:

var value = editor.val();
editor.val("");
editor.focus();
editor.val(value);

這是工作小提琴: http//jsfiddle.net/vyshniakov/p37ax/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM