js清空文本框:
TextBox 服务器,客户端都清空
/// <summary>
/// 清空文本框
/// </summary>
/// <param name="controls"></param>
public void EmptyTextBox(ControlCollection controls)
{
foreach (Control c in controls)
{
if (c.Controls.Count > 0)
{
// 递归
this.EmptyTextBox(c.Controls);
}
else if (c is TextBox)
{
// 服务器控件
((TextBox)c).Text = "";
}
else if (c is HtmlInputText)
{
// HTML 控件
((HtmlInputText)c).Value = "";
}
}
}
/// 清空文本框
/// </summary>
/// <param name="controls"></param>
public void EmptyTextBox(ControlCollection controls)
{
foreach (Control c in controls)
{
if (c.Controls.Count > 0)
{
// 递归
this.EmptyTextBox(c.Controls);
}
else if (c is TextBox)
{
// 服务器控件
((TextBox)c).Text = "";
}
else if (c is HtmlInputText)
{
// HTML 控件
((HtmlInputText)c).Value = "";
}
}
}
js前台清空
点击按钮用Javascript清空页面上所有的文本框|文本域,代码如下:
<script type="text/javascript">
<!--
function cls(){
var sum=0;
var t = document.getElementsByTagName_r("INPUT");
for (var i=0; i <t.length;i++){
if (t[i].type=='text'){
++sum;
t[i].value="";//清空
}
}
var sum1=0;
var t1 = document.getElementsByTagName_r("textarea");
for (var i1=0; i1 <t1.length;i1++){
if (t1[i1].type=='textarea'){
++sum1;
t1[i1].value="";//清空
}
}
alert('页面共有TEXT:'+sum + ' 个\n' + '页面共有TextArea:' + sum1 +'个');
}
//-->
<script type="text/javascript">
<!--
function cls(){
var sum=0;
var t = document.getElementsByTagName_r("INPUT");
for (var i=0; i <t.length;i++){
if (t[i].type=='text'){
++sum;
t[i].value="";//清空
}
}
var sum1=0;
var t1 = document.getElementsByTagName_r("textarea");
for (var i1=0; i1 <t1.length;i1++){
if (t1[i1].type=='textarea'){
++sum1;
t1[i1].value="";//清空
}
}
alert('页面共有TEXT:'+sum + ' 个\n' + '页面共有TextArea:' + sum1 +'个');
}
//-->