extjs4用图像问题替换按钮

Mic*_*eal 1 javascript extjs extjs-mvc extjs4.1

所以我正在尝试用图像替换extjs按钮并让它显示一些工具提示.问题是我只想显示图像,我不想要extjs按钮的背景.这是我的代码如下.为了了解我在说什么,这里是js小提琴:http: //jsfiddle.net/nCkZN/7/

CSS:

.question {
    background-image: url(../www/css/slate/btn/question.png) !important;
    background-repeat: no-repeat;
}
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

{
    xtype: 'button',
    iconCls: 'question',
    tooltip: "<b>read-only</b>:Read-only users will have read only access to all pages<br> ",
    padding: '2 6 2 7',
    width: 20,
    height: 24
}
Run Code Online (Sandbox Code Playgroud)

编辑:我用文本替换了按钮,只显示图像.但它并没有显示工具提示.

{
    xtype: 'text',
    cls: 'question',
    tooltip: "<b>read-only</b>:Read-only users will have read only access to all pagess ",
    height: 20,
    padding: '12 6 2 7'
}
Run Code Online (Sandbox Code Playgroud)

Jua*_*des 6

您可以通过CSS http://jsfiddle.net/nCkZN/10/修改按钮的外观

Ext.create('Ext.form.Panel', {
    title: 'Contact Info',
    width: 300,
    bodyPadding: 10,
    renderTo: Ext.getBody(),
    items: [{
        xtype: 'button',
        cls: 'my-btn', // Add this so you can style the button
        iconCls:'questionIcon',
        tooltip:"<b>read-only</b>:Read-only users will have read only access to all pages<br> ",
        padding: '2 6 2 7'                    
    }]
});?
Run Code Online (Sandbox Code Playgroud)

CSS

.questionIcon {
  background-image:url(http://www.myimage.com/pic.png) !important;
  background-repeat: no-repeat;            
}

.my-btn {
  border-radius: 0;
  background-image: none;
  border: 0;
}
Run Code Online (Sandbox Code Playgroud)

您也可以使用常规Ext.Img并添加工具提示.当您不想要按钮时,似乎比使用按钮更干净.http://jsfiddle.net/nCkZN/15/

Ext.create('Ext.form.Panel', {
    title: 'Contact Info',
    width: 300,
    bodyPadding: 10,
    renderTo: Ext.getBody(),
    items: [{
        xtype: 'image',
        src:'http://www.southampton.ac.uk/isolutions/computing/elearn/blackboard/small_pen.gif',
        padding: '2 6 2 7',
        listeners: {
            render: function(cmp) {
                Ext.create('Ext.tip.ToolTip', {
                    target: cmp.el,
                    html: "<b>read-only</b>:Read-only users will have read only access to all pages<br> "
                });
            }
        }
    }]
});?
Run Code Online (Sandbox Code Playgroud)

你真正想要的是一种向任何组件添加工具提示的方法.这是一个插件来做到这一点.

Ext.define('Ext.ux.Tooltip', {
    extend: 'Ext.AbstractPlugin',
    alias: 'plugin.ux-tooltip',

    /**
     * @cfg html The text to put into the tooltip
     */
    init: function(cmp) {
        var me = this;
        cmp.on('render', function() {
            Ext.create('Ext.tip.ToolTip', {
                target: cmp.el,
                html: me.html
            });        
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

现在很容易为任何组件添加工具提示http://jsfiddle.net/nCkZN/17/

Ext.create('Ext.form.Panel', {
    title: 'Contact Info',
    width: 300,
    bodyPadding: 10,
    renderTo: Ext.getBody(),
    items: [{
        xtype: 'image',
        src:'http://www.southampton.ac.uk/isolutions/computing/elearn/blackboard/small_pen.gif',
        padding: '2 6 2 7',
        plugins: {
            ptype: 'ux-tooltip', 
            html: '<b>read-only</b>:Read-only users will have read only access to all pages<br> '
        }
    }]
});
Run Code Online (Sandbox Code Playgroud)