【问题标题】:Dynamically display a message when text box in clicked单击文本框时动态显示消息
【发布时间】:2013-04-25 12:35:56
【问题描述】:

如何在单击文本字段/具有任何值以及删除文本字段的内容时动态显示消息,该消息必须消失

【问题讨论】:

  • 您到底想完成什么?这是某种验证吗?
  • 不是验证。一旦我完成为我的文本字段提供值,必须在文本字段旁边显示一条警报消息,一旦我清除该字段,警报消息也应该被清除。!

标签: extjs textbox extjs4 onclicklistener keylistener


【解决方案1】:

您可以在文本字段上使用侦听器。我没有测试过下面的代码,但是你可以试试类似的。

{
    xtype: 'textfield',
    messageTip: undefined,
    listeners: {
        afterrender: function(text) { //Textfield doesn't have a click even't so use afterrender to put a click event on the element
            //U can use text.inputEl.on({ aswell to only get the input element and not the label
            text.getEl().on({
                click: function() {
                     //Create tip here
                     text.messageTip = Ext.create('Ext.tip.Tip', {
                         //Configuration
                     }).show();
                }
            });
        },
        keypress: function(text) {
            if (text.getValue() == '') {
                //hide the message
                text.messageTip.hide()
            }
        }
    }
}

【讨论】:

    【解决方案2】:

    您可以在文本字段上使用“更改”侦听器:

    {
        xtype: 'textfield',
        listeners : {
            change: function(field, newValue, oldValue, options)) {
                       if(newvalue!=''){
                           Message=Ext.create('Ext.tip.ToolTip', {
                           closable:true,
                           hideDelay : 3000,
                           padding: '0 0 0 0',
                           maxWidth:400,
                           width:800,
                           html: ".......",
                          }).showAt([x, y]); 
                            }
                      else Message.hide();
                        }
                    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-12
      • 1970-01-01
      • 1970-01-01
      • 2016-04-07
      • 2021-07-30
      • 1970-01-01
      相关资源
      最近更新 更多