更改控件背景色,如textfield

本文介绍了一个使用ExtJS库实现的颜色选择器组件示例。该示例展示了如何通过Ext.menu.ColorMenu创建一个颜色选择菜单,并将其绑定到按钮上。当点击按钮时,会弹出颜色选择窗口,用户可以选择颜色并应用于指定元素的背景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Ext.onReady( function() {
var colorShowId = '';

function showColor(id) {
colorShowId = id;
var colorText = Ext.getCmp(id);
colorWin.x = colorText.getPosition()[0] + colorText.getWidth();
colorWin.y = colorText.getPosition()[1];
colorWin.show();
}

var menu = new Ext.menu.ColorMenu({
listeners: {
select: function(picker, selColor) {
var color = '#' + selColor;
Ext.getDom(colorShowId).style.background = color;
colorWin.hide();
}
}
});


var colorWin = new Ext.Window( {
title : 'yyy',
constrain : true,
layout : 'fit',
plain : true,
width : 380,
height : 300,
closeAction : 'hide',
animCollapse : true,
animateTarget : Ext.getBody(),
modal : true,
items : [
{
xtype : 'button',
text : 'hzy',
menu : menu
}
]
}) ;


var form = new Ext.form.FormPanel({
width:200,
items : [
{
xtype : 'textfield',
id : 'aa',
fieldLabel : 'xxxxxx'
}
],
buttonAlign : 'center',
buttons: [{
text: 'xxx',
style:'background:red',
handler: function(btn) {
showColor('aa');
}
} ]
});
var viewport = new Ext.Viewport({
layout : 'fit',
items : [form]
});
viewport.doLayout();
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值