加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

asp.net中重置按钮的实现

(2013-02-18 17:40:11)
分类: ASP.NET

一 . 程序实现的方法
 
   //重置按钮事件
    protected void btn_Reset_Click(object sender, EventArgs e)
    {
        this.FindButton(this);
    }
    private void FindButton(Control c)
    {
        if (c.Controls != null)
        {

            foreach (Control x in c.Controls)
            {
                if (x is System.Web.UI.WebControls.TextBox)
                {
                    ((System.Web.UI.WebControls.TextBox)x).Text = "";
                }
                FindButton(x);
            }
        }
    }

二. javascript 实现方法

function ClearTextBoxValue()

{

        for(i=0;i

        {

                if(window.document.forms[0].elements[i].type=="text")         

                {

                       window.document.forms[0].elements[i].value="";

                }

        }

        return false;

}
后台调用代码如下:

this.btnReset.Attributes.Add("onclick","return ClearTextBoxValue()");

 

其他:

http://zhidao.baidu.com/question/91812157.html

http://zhidao.baidu.com/question/69411739.html

 

Leon:

更简单的方法:在“重填”按钮属性中的"onclientclick"中输入“javascript:document.forms[0].reset()”

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有