如何在Extjs 4标签上添加click事件

zour9fqk  于 2024-01-07  发布在  其他
关注(0)|答案(6)|浏览(187)

我尝试在extjs4中添加标签上的单击事件,但不起作用

  1. Ext.onReady(function() {
  2. var ResetLabel = new Ext.form.Label({
  3. id:'ResetLabel',
  4. text: 'click it',
  5. renderTo : document.body
  6. });
  7. alert(Ext.getCmp('ResetLabel').id);
  8. Ext.getCmp('ResetLabel').on('click',function(){
  9. alert("message");
  10. });
  11. });

字符串
如何在标签上添加事件?

deyfvvtc

deyfvvtc1#

此代码在Extjs 4中工作

  1. Ext.onReady(function() {
  2. var ResetLabel = new Ext.form.Label({
  3. id:'ResetLabel',
  4. text: 'click it',
  5. renderTo : document.body
  6. });
  7. alert(Ext.getCmp('ResetLabel').getEl());
  8. Ext.getCmp('ResetLabel').getEl().on('click',function(){
  9. alert("message");
  10. });
  11. });

字符串

展开查看全部
3yhwsihp

3yhwsihp2#

  1. {
  2. xtype: 'label',
  3. listeners: {
  4. element: 'el',
  5. click: function () { alert(); }
  6. }
  7. }

字符串

bwitn5fc

bwitn5fc3#

试试这个:

  1. Ext.onReady(function() {
  2. var ResetLabel = new Ext.form.Label({
  3. id:'ResetLabel',
  4. text: 'click it',
  5. listeners: {
  6. click: function(){
  7. alert("message");
  8. }
  9. },
  10. renderTo : document.body
  11. });
  12. alert(Ext.getCmp('ResetLabel').id);
  13. });

字符串

展开查看全部
dpiehjr4

dpiehjr44#

对我来说也不起作用,试过所有的例子...
检查一下,这个工作

  1. var ResetLabel = new Ext.form.Label({
  2. id:'ResetLabel',
  3. text: 'click it'
  4. });
  5. Ext.onReady(function() {
  6. Ext.getCmp('ResetLabel').getEl().on('click',function(){
  7. alert("message");
  8. });
  9. });

字符串
我正在将ResetLabel添加到面板中。

b0zn9rqh

b0zn9rqh5#

我正在ExtJS 3.4的基础上处理一个旧的代码库,下面的代码对我来说很有效。我想它也应该对更高的版本有效。

  1. new Ext.form.Label({
  2. "html": "Halp!",
  3. "listeners": {
  4. /* We are going to assing the click event right after the element has rendered */
  5. "afterrender": function () {
  6. this.getEl().on( "click", function () {
  7. console.log( "Clicked!" );
  8. });
  9. }
  10. }
  11. });

字符串

lbsnaicq

lbsnaicq6#

我喜欢短一点,以便更快地理解这个想法:

  1. // Adding abcent label event through its dom-structure:
  2. myLabel.getEl().on(
  3. "click",
  4. onClickMyLabel);

字符串

相关问题