日期:2014-05-19  浏览次数:20871 次

批量清设定表框和文本框的内容
在一个表格中,有多个控件,都只是文本框和下拉列表,

我想用一个方法把所有的广西框置为空,把所有下拉框的value都置为0.



------解决方案--------------------
js

var controls = document.getElementsByTagName( "input ");
for(var i = 0;i <controls.length;i++){
var control = controls[i];
if(control.value){
control.value = ' '
}
}

var controls = document.getElementsByTagName( "select ");
for(var i = 0;i <controls.length;i++){
var control = controls[i];
if(control.selectedIndex){
control.selectedIndex = 0;
}
}

CS:

foreach(Control control in this.Controls)
{
if(control is TextBox)
{
TextBox txt = control as TextBox;
txt.Text = " ";
}
if(control is ...
}
------解决方案--------------------
foreach (Control ctl in this.panel4.Controls)
{
if (ctl.Name == "TextBox ")
{
ctl.Text = " ";
}
}