1. 内置监听器 listeners
Ext.create('Ext.Button', {
               renderTo: Ext.getElementById('helloWorldPanel'),
               text: 'My Button',
               listeners: {
                  click: function() {
                     Ext.MessageBox.alert('Alert box', 'Button is clicked');    
                  }
               }
            });
  1. 附加事件监听 Ext.on
button.on('click', function() {
               Ext.MessageBox.alert('Alert box', 'Button is clicked');
            });
  1. 自定义事件
<!DOCTYPE html>
<html>
    <head>
        <link
            href="./ext-6.0.0-gpl/ext-6.0.0/build/classic/theme-neptune/resources/theme-neptune-all.css"
            rel="stylesheet"
        />
        <script src="./ext-6.0.0-gpl/ext-6.0.0/build/ext-all.js"></script>
        <script type="text/javascript">
            Ext.onReady(function () {
              var button = Ext.create('Ext.Button', {
                renderTo: Ext.getElementById('helloWorldPanel'),
                text: 'My Button',
                listeners: {
                  myEvent: function(button) {
                    Ext.MessageBox.alert('Alert box', 'My custom event is called')
                  }
                }
              })
              Ext.defer(function() { //用于延迟执行
                button.fireEvent('myEvent') //触发事件
              }, 5000)
            })
        </script>
    </head>
    <body>
        <div id="helloWorldPanel"></div>
    </body>
</html>

零号
1 声望0 粉丝