繁体   English   中英

Textarea自动向下滚动

[英]Textarea Auto scroll down

我知道这可以通过.change()事件完成,并放入$('#console').scrollTop($('#console')[0].scrollHeight); 但是问题是textarea是只读的,我正在使用javascript在textarea中输入文本。

例如:

$('#console')。text($('#console')。text()+'\\ n> _ Optained Trigger');

在这种情况下,textarea不会滚动到底部,因为更改事件没有响应。

是否有其他选择或捕获textarea中的javascript文本更改的任何其他事件?

您可以链接影响元素的jQuery操作,而无需事件:

$('#console').text($('#console').text()+'\n>_ Optained Trigger').scrollTop($('#console')[0].scrollHeight);

编辑:好的,我阅读了您的评论,并解决了您可以手动触发更改事件的问题

//first define the event behaviour
$('#console').on('change', function(e){
    var console = $(this);
    console.scrollTop($('#console')[0].scrollHeight);
}

//then every time you modify the text, trigger the event
$('#console').text($('#console').text()+'\n>_ Optained Trigger').trigger('change')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM