foreach (var i in Controls) { TextBox tb = i as TextBox; if (tb != null) tb.Text = "0"; }
foreach (Control aa in Page.Controls) { if (aa is TextBox ) { TextBox tb = (TextBox )aa; tb.Text = ""; } }
递归 public static void ResetTextBox(Control control) { if (control.HasChildren) { foreach (Control subControl in control.Controls) { if (subControl is TextBox) (subControl as TextBox).Text = string.Empty; else ResetTextBox(subControl); } } }
是这个意思不?
function SetTextBox()
{
var txts = document.getElementsByTagName('INPUT');
for(var i = 0; i < txts.length; i++)
{
if (txts[i].type.toUpperCase() == 'TEXT')
{
txts[i].value = "";
}
}}//按钮的onclick="SetTextBox()"
//如果是服务器按钮 OnClientClick="SetTextBox()"
用JavaScript遍历页面上的TextBox设置其值为:0
{
TextBox tb = i as TextBox;
if (tb != null) tb.Text = "0";
}
{
if (aa is TextBox )
{
TextBox tb = (TextBox )aa;
tb.Text = "";
}
}
{
if (control.HasChildren)
{
foreach (Control subControl in control.Controls)
{
if (subControl is TextBox)
(subControl as TextBox).Text = string.Empty;
else
ResetTextBox(subControl);
}
}
}
js就document.getElementByTagName()
{
foreach (Control c in cs)
{
if (c is TextBox)
{
c.Text = "";
}
}
}
这个不是递归吧,如果subcontrol的control的control里还有textbox呢?
foreach(Control c in this.Controls)
{
if(c is TextBox)
{
(c as TextBox).Text = "0";
}
}
{
try
{
foreach (Control ctrl in pnlIn.Controls)
{
Label lable = new Label();
if (ctrl.GetType() != lable.GetType())
{
ctrl.Text = 0;
}
}
}
}
foreach(Control c in this.Controls)
{
if(c is TextBox)
{
(c as TextBox).Text = "0";
}
}
除了这个还可以用容器,当然窗体也是个容器.方法多了
{
foreach (object item in this.Controls)
{
if (item is TextBox)
{
TextBox tt = item as TextBox;
tt.Text = "";
}
else
{
continue;
}
}
}我这个方法比较简单,已经试过, 我是新手,勿笑.
$(":input").foreach(function(i){
$(this).val("");
});
如果是textBox就把它置为空或者为0,就OK了
///声明:本人新手一名
///本人测试代码 protected void Button1_Click(object sender, EventArgs e)
{
foreach(Control aa in Page.Controls )
if (aa is TextBox)
{
TextBox tb = (TextBox)aa;
tb.Text= " ";
}
}怎么点击Button1 没反应 求解。谢谢大虾们。。
遍历页面上所有的TextBox控件并将其设置为空值