把所有的TextBox 放入placeholder中 然后再用 For Each txtCtrl In ph1.Controls If TypeOf txtCtrl Is TextBox Then txtCtrl.Attributes.Add("onfocus", "this.style.backgroundColor='#ffffc0';") txtCtrl.Attributes.Add("onblur", "this.style.backgroundColor='#ffffff';") End If Next txtCtrl
把所有的TextBox 放入placeholder中 然后再用 For Each txtCtrl In ph1.Controls If TypeOf txtCtrl Is TextBox Then txtCtrl.Attributes.Add("onfocus", "this.style.backgroundColor='#ffffc0';") txtCtrl.Attributes.Add("onblur", "this.style.backgroundColor='#ffffff';") End If Next txtCtrl
Me.Controls应该应该是页面下的控件个数,不包括控件下的子控件,如果一定要用循环,你可以试一试用递归的方法添加控件属性
If TypeOf txtCtrl Is TextBox Then
txtCtrl.Attributes.Add("onfocus", "this.style.backgroundColor='#ffffc0';")
txtCtrl.Attributes.Add("onblur", "this.style.backgroundColor='#ffffff';")
End If
Next txtCtrl
If TypeOf txtCtrl Is TextBox Then
txtCtrl.Attributes.Add("onfocus", "this.style.backgroundColor='#ffffc0';")
txtCtrl.Attributes.Add("onblur", "this.style.backgroundColor='#ffffff';")
End If
Next txtCtrl