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<window.document.forms[0].elements.length;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()");


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM