最近做项目,客户要求选择combobox下拉在选择的时候,输入框能够随着选择不同颜色不同。研究了一下,代码如下,希望能够给大家一点思路(重点在红字)。
$("#id").combobox({
valueField:'value',textField:'label',
panelHeight:120,
onSelect:function(index){
if(index.value=="2"){
this.nextSibling.firstChild.style.background="#00FF00";
}else if(index.value=="1"){
this.nextSibling.firstChild.style.background="#FFFF00";
}else if(index.value=="0"){
this.nextSibling.firstChild.style.background="#FF0000";
}
},
data: [{
label: '运行',
value: '2'
}, {
label: '备用',
value: '1'
}, {
label: '检修',
value: '0'
}]
});
然后还有js修改input颜色的方法:也可以借鉴一下
document.getElementById(i).style.backgroundColor = "#00FF00";