javascript - 使用 jQuery 在 textarea 中向下滚动

标签 javascript jquery html

<h2>Greetings</h2>
<div class="container">
  <div class="inner">
    Hello
    <p>Test</p>
  </div>
  <textarea id="one" class="inner">
    Goodbye
</textarea>
</div>

$("#one").append("your text to append");
$("#one").append("your text to append");
$("#one").append("your text to append");
$("#one").append("your text to append");

直播:http://jsfiddle.net/tGFmq/

如何让文本区域自动向下滚动?

最佳答案

将此位添加到您的代码中(最好在您插入的任何内容的末尾):

    var psconsole = $('#one');
    if(psconsole.length)
       psconsole.scrollTop(psconsole[0].scrollHeight - psconsole.height());

关于javascript - 使用 jQuery 在 textarea 中向下滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8467368/

相关文章:

javascript - 查找具有特定键值对的 JS 对象/哈希

jquery - 单击按钮上的表行获取值 jquery

html - CSS 未加载

javascript - Vue.js 的引导表/分页中的数据问题

javascript - 在忽略文字的换行符处拆分模板字符串\n

javascript - Node Js - mssql 的 TransactionError (ENOTBEGUN)

javascript - NodeJS 结合对象数组范围属性

javascript - 在 jQuery 中订阅 "childrenAdded"事件

javascript - 为什么我得到 'TypeError: Cannot read property ' length' of undefined'

javascript - bootstrap 和 jquery 数据表,将按钮成功更改为危险和文本