日期:2014-05-16  浏览次数:20355 次

ext button 问题
toolbar 上加载了一个button,ID为slbutton,想在用户点击时修改此button的背景颜色,该怎么办?
另外,使用这样的方式,Ext.getCmp("slbutton").setText("ab"),为啥没有效果呢?
------解决方案--------------------
本帖最后由 showbo 于 2014-02-14 10:16:46 编辑
 Ext.getCmp方法要配置id,不是itemId,不要搞错了。

配置itemId需要使用父容器的getComponent方法
<style>
.focusbtn button{background:#f00}
</style>
<script type="text/javascript">
    Ext.onReady(function () {
        Ext.create('Ext.Button', {
            text: 'Button',
            renderTo: Ext.getBody(),
            id: 'slbutton',////////
            listeners: {
                click: function () {
                    Ext.getCmp('slbutton').setText('ab').addCls('focusbtn');
                }
            }
        });

    });
</script>

------解决方案--------------------
function include_css(path) {
    var fileref = document.createElement("link")
    fileref.rel = "stylesheet";
    fileref.type = "text/css";
    fileref.href = path;
document.getElementsByTagName('head')[0].appendChild(fileref);/////
}
include_css("../Index/css/myminu.css");
function InitializePage()
{
    configs = { text: '矢量图', width: 50, id: 'slButton' };
    vectorButton = Ext.create('Ext.Button', configs);
    vectorButton.on("click", vectorButton_click_handler);
    function vectorButton_click_handler(item, e, options) {
        
        Ext.getCmp('slButton').setIconCls('buttondesinger'); //在../Index/css/myminu.css文件中
        。。。
}


不要在事件中导入,直接导入

要不因为css要加载,你的代码第一次可能看不到效果什么的