教你如何写Extjs插件

本文转载自:http://czpae86.iteye.com/blog/691683,作者:czpae86

在项目开发中,难免会用到Extjs写插件来实现需求,有一些功能写插件就可以搞定的,无需重新封装一个类。

下面用一个以前写的插件来讲解。

 

插件功能说明:

1,实现功能:鼠标放在文本框上面时提示信息,鼠标离开后提示信息消失。

2,要求:提示信息可以自定义。

 

代码讲解:

Fieldtips代码

FieldTips = Ext.extend(Object, {  
    init : function(f){  
        this.field = f;  
        if(f.msg){  
            this.tips = new Ext.ToolTip({  
                html : '<div style="margins:0px 0px 0px 2px">'+ f.msg +'</div>'  
            });  
        }  
        f.on('afterrender',this.initTips, this);  
    },  
    initTips : function(){  
        this.field.el.on('mouseover', this.showTips, this);  
        this.field.el.on('mouseout', this.hideTips, this);  
    },  
    showTips : function(e, t, o){  
        if(this.tips)this.tips.showAt(e.getXY());  
    },  
    hideTips : function(e, t, o){  
        if(this.tips)this.tips.hide();  
    }  
});  

 使用fieldtips插件代码

var fp = new Ext.FormPanel({  
        labelWidth: 75,   
    labelAlign:'right',  
        frame:true,  
        title: '测试',  
        bodyStyle:'padding:5px 5px 0',  
        width: 350,  
        defaults: {width: 230},  
        defaultType: 'textfield',  
    items: [{  
        fieldLabel: '标题',  
        name: 'title',  
        plugins : new FieldTips(),  
        msg : "来匆匆去冲冲!"  
    },{  
        fieldLabel: '内容',  
        xtype : "textarea",  
        name: 'content',  
        plugins : new FieldTips(),  
        msg : "请您写下宝贵的建议,吾万分感谢!"  
    }]  
}).render(document.body);

 运行效果图:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值