在Extjs Textfield上设置背景颜色

oor*_*ile 5 css textbox extjs

我试图在其值大于75时将背景颜色设置为文本字段.所以我将以下代码添加到监听器

listeners: {
       beforeRender: function(e) {
           if (someValue >= 75) {
               e.style = " background-color: #00CC99";
           }
       }
 }
Run Code Online (Sandbox Code Playgroud)

但是当它呈现时我得到类似下面的东西,

在此输入图像描述

有没有办法让绿色在整个文本框中可见而不仅仅是buttom?我发现由于默认的CSS背景图像,它没有按预期显示.但我想改变价值变化的CSS而不是只为一个文本框写单独的CSS.有办法吗?

Zet*_*eta 6

摆脱背景图片:

e.style = "background-image:none;background-color:#00cc99;";
/* or */
e.style = "background:none #00cc99;";
Run Code Online (Sandbox Code Playgroud)

如果e是DOM对象使用element.style.property = 'value':

e.style.backgroundImage = 'none';
e.style.backgroundColor = '#00cc99';
/* or */
e.style.background = 'none #00cc99';
Run Code Online (Sandbox Code Playgroud)

为了完整性,ExtJS中的定义(根据ExtJS"表单字段类型"演示):

.x-form-field,.x-form-text{
    /* ... */
    background:url("../../resources/themes/images/default/form/text-bg.gif") 
         repeat-x scroll 0pt 0pt white;
}
Run Code Online (Sandbox Code Playgroud)

  • 我得到了它,我使用e.style来设置不起作用的值,所以我用firebug来查看这个元素实际上有什么,原来在"e"的"el"对象中有一个名为setStyle的方法.所以我把它改成了e.el.setStyle("background-image","none"); e.el.setStyle("background-color","#00cc99"); 哪作得很好.谢谢 (2认同)