如何使用 ExtJS 更改文本字段的颜色?

发布于 2025-01-04 14:46:33 字数 534 浏览 3 评论 0原文

我想更改 ExtJS 文本字段的颜色,但没有成功。标签是获取颜色的组件:

var textfield= Ext.create('Ext.form.Text', 
    {
        id: 'textfield',
        name: 'name',
        fieldLabel: 'Name',
        style: 'background-color: #ddd;',
        allowBlank: false,
    });

Ext.create('Ext.form.Panel', {
    title: 'Contact Info',
    width: 300,
    bodyPadding: 10,
    renderTo: Ext.getBody(),
    items: [textfield]
});

示例: http://jsfiddle.net/3ZZcZ/

如何更改颜色?

I would like to change the color of a ExtJS textfield, but I don´t succeed. The label is the component that gets the color:

var textfield= Ext.create('Ext.form.Text', 
    {
        id: 'textfield',
        name: 'name',
        fieldLabel: 'Name',
        style: 'background-color: #ddd;',
        allowBlank: false,
    });

Ext.create('Ext.form.Panel', {
    title: 'Contact Info',
    width: 300,
    bodyPadding: 10,
    renderTo: Ext.getBody(),
    items: [textfield]
});

Example:
http://jsfiddle.net/3ZZcZ/

How do I change the color?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

俏︾媚 2025-01-11 14:46:33

您需要设置 fieldStyle 而不是 style。您还需要覆盖 Ext JS 默认值,该默认值在字段上设置背景图像。像这样:

fieldStyle: 'background-color: #ddd; background-image: none;'

You need to set fieldStyle instead of style. You also need to override the Ext JS default, which sets a background image on the field. Like this:

fieldStyle: 'background-color: #ddd; background-image: none;'
一杯敬自由 2025-01-11 14:46:33

解决此问题的更好方法是将 fieldCls 属性设置为 CSS 类。

像这样:

字段配置:

fieldCls: 'required'

CSS:

.required {
    background-image:none;
    background-color:#FFFFCC;
}

A better way to approach this is to set the fieldCls attribute to a CSS class.

Like this:

Field Config:

fieldCls: 'required'

CSS:

.required {
    background-image:none;
    background-color:#FFFFCC;
}
请别遗忘我 2025-01-11 14:46:33

你可以通过多种方式做到这一点

选项1(全局):更改“Ext.form.field.Text”的SASS变量值

eg: $form-text-field-color: #003168 !default;

选项2:创建一个mixin

eg:

file -> sass/src/form/field/Text.scss

@include extjs-text-field-ui(
    $ui: 'customName',
    $ui-color: #003168
);

js: 
    {
        xtype: 'textfield',
        ui: 'customName'
    }

选项3:使用表单字段的“fieldStyle”配置

eg:
{
    xtype: 'textfield',
    fieldLabel: 'Test Label',
    fieldStyle: 'font-weight: bold; color: #003168;',
    labelWidth: 170
}

选项4:添加“cls” " 形成字段并将样式添加到 css 文件中

eg: 
js:
{
    xtype: 'form',
    defaults: {
        cls: 'test-class'
    }
}

CSS:
.test-class .x-form-text {
    color: #003168;
}

You can do it in many ways

Option 1(Global): Change the SASS variable value of "Ext.form.field.Text"

eg: $form-text-field-color: #003168 !default;

Option 2: Create a mixin

eg:

file -> sass/src/form/field/Text.scss

@include extjs-text-field-ui(
    $ui: 'customName',
    $ui-color: #003168
);

js: 
    {
        xtype: 'textfield',
        ui: 'customName'
    }

Option 3: use form field's "fieldStyle" config

eg:
{
    xtype: 'textfield',
    fieldLabel: 'Test Label',
    fieldStyle: 'font-weight: bold; color: #003168;',
    labelWidth: 170
}

Option 4: add "cls" to form field and add your style to your css file

eg: 
js:
{
    xtype: 'form',
    defaults: {
        cls: 'test-class'
    }
}

CSS:
.test-class .x-form-text {
    color: #003168;
}
傾城如夢未必闌珊 2025-01-11 14:46:33

扩展瓦西里的答案。样式可以动态设置,如下所示:

Ext.get('textfield').setStyle('background-color','#ddd');
Ext.get('textfield').setStyle('background-image','none');

Expanding on Vasiliy's answer. The style can be set dynamically as follows:

Ext.get('textfield').setStyle('background-color','#ddd');
Ext.get('textfield').setStyle('background-image','none');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文