我的表单中有81个RichTextBox(Sudoku Solver),我希望它们在用户输入数据时变为灰色,并且当没有数据(例如已经过时或从未在那里)保持白色时。我该如何管理?
答案 0 :(得分:2)
使用EventHandler
!
来自MSDN
private void TextChangedEventHandler(object sender, EventArgs e)
{
TextBox tb = sender as TextBox;
if(tb != null){
if(tb.Text.Length > 0){
//set color
}
else{
//set color
}
}
}
...
//Loop through your controls (textboxes) and set handler
foreach(Control c in this.Controls){
if(c is TextBox){
c.TextChanged += TextChangedEventHandler;
}
}
答案 1 :(得分:-2)
$(".test").on("change keyup paste click", function() {
if(this.val()=="")
{
this.css('background-color', '#ffff00');
}
else
{
this.css('background-color', '#ffff55');
}
})