如何使用 ExtJS 更改文本字段的颜色?
我想更改 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要设置
fieldStyle
而不是style
。您还需要覆盖 Ext JS 默认值,该默认值在字段上设置背景图像。像这样:You need to set
fieldStyle
instead ofstyle
. You also need to override the Ext JS default, which sets a background image on the field. Like this:解决此问题的更好方法是将 fieldCls 属性设置为 CSS 类。
像这样:
字段配置:
CSS:
A better way to approach this is to set the fieldCls attribute to a CSS class.
Like this:
Field Config:
CSS:
你可以通过多种方式做到这一点
选项1(全局):更改“Ext.form.field.Text”的SASS变量值
选项2:创建一个mixin
选项3:使用表单字段的“fieldStyle”配置
选项4:添加“cls” " 形成字段并将样式添加到 css 文件中
You can do it in many ways
Option 1(Global): Change the SASS variable value of "Ext.form.field.Text"
Option 2: Create a mixin
Option 3: use form field's "fieldStyle" config
Option 4: add "cls" to form field and add your style to your css file
扩展瓦西里的答案。样式可以动态设置,如下所示:
Expanding on Vasiliy's answer. The style can be set dynamically as follows: