【问题标题】:Ext JS - How to Scroll to bottom of TextareaExt JS - 如何滚动到 Textarea 的底部
【发布时间】:2012-06-09 21:20:27
【问题描述】:

这是我下面的代码。如何滚动到文本区域的底部? 应该是这样的

Ext.getCmp('output').setScrollPosition(Ext.getCmp('output').getScrollHeight());

这是我的 textarea 代码:

var myWin= new Ext.Window({
            height        :    340,
            title        :    'CHAT',
            modal        :    true,
            resizable    :    false,
            draggable    :    false,
            closable     :    false,
            width        :    477,
            layout       : 'absolute',
            bodyStyle    :    'padding : 10px',
            buttonAlign  : 'center',
            items        :    [
            {
                id           :    'output',
                xtype        :    'textarea',
                width        :    216,
                readOnly     :    true,
                autoScroll   :    true,
                height       :    234,
                x            :    10,
                y            :    10
            },
            item6,
            {
                id       :    'input',
                xtype    :    'textfield',
                width    :    443,
                y        :    249,
                x        :    10
            }]

...

【问题讨论】:

    标签: javascript extjs extjs3


    【解决方案1】:

    我认为没有 ExtJs 方法可以滚动 textarea,但是您可以使用 HTML textarea 属性:

    var t = Ext.getCmp('output'),
       t1 = t.getEl().down('textarea');
    t1.dom.scrollTop = 99999;
    

    这是讨论的问题:Dynamically Scrolling a Textarea

    【讨论】:

    • 我修改了你的代码:var t = Ext.getCmp('output'), t1 = t.getEl(); t1.dom.scrollTop = 99999;
    • 但是,它似乎在 Google Chrome 中不起作用。我正在检查它。
    • 确保组件被渲染。否则 getEl() 返回未定义。这对我有用:if(t.rendered) t.getEl().down('textarea').dom.scrollTop = 99999;
    【解决方案2】:
    var d = Ext.getCmp('output').getEl().down('textarea').dom;
    d.scrollTop = d.scrollHeight - d.offsetHeight;
    

    【讨论】:

      猜你喜欢
      • 2020-04-08
      • 2016-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-11
      • 2014-07-13
      • 2012-02-28
      相关资源
      最近更新 更多