表格每行的第一列有一个复选框:<input type='checkbox' name=cb>
表格的上面有一个删除按钮: <input type = "button" onclick = "delete()" value="删除">
单击这个删除按钮会激发一个JS事件,来取到该行的ID:
 <script language = "javascript">
                function delete()
        {
                 for(i=0;i<document.f1.cb7.length;i++)
                 {
                     if(document.f1.cb7[i].checked == true)
                     {
                        var index = document.f1.cb7[i].parentElement.parentElement.parentElement.rows(i).cells(1).innerText;
                     }
                 }
        }    </script>现在ID可以取到,我想在取到该行的ID后,弹出一个确认删除的对话框,如果选是,执行删除数据库的PHP或ASP代码,请问怎么实现啊?

解决方案 »

  1.   

    c#的if(MessageBox.show() == DialogResult.Yes){}就可以解决
      

  2.   

    if(confirm("确认要删除吗?")){
    //执行删除
    }
      

  3.   

    function delete()
            {
                     for(i=0;i<document.f1.cb7.length;i++)
                     {
                         if(document.f1.cb7[i].checked == true)
                         {
                            var index = document.f1.cb7[i].parentElement.parentElement.parentElement.rows(i).cells(1).innerText;
                           if(window.confirm("are you sure to delete?"){
                                  doDelete();
                             }
                         }
                     }
      

  4.   

    if(confirm("删除?"))
    {
       //提交页面,或者链接到其他页.
    }
      

  5.   

    private void del_Click(object sender, System.EventArgs e)
    {
    int index;
    index=Session["module_authority"].ToString().IndexOf("80");
    if(index>0)
    {
    string ID="",Selected_Date="";
    foreach(RepeaterItem item in this.Repeater.Items)
    {
    CheckBox ck=(CheckBox)item.FindControl("checkbox_del");
    if(ck.Checked)
    {
    HtmlInputHidden inputhidden = (HtmlInputHidden)item.FindControl("SelectedID");
    ID +=inputhidden.Value.Trim()+",";
    HtmlInputHidden inputhidden2 = (HtmlInputHidden)item.FindControl("Selected_Date");
    Selected_Date +=inputhidden2.Value.Trim()+",";
    }
    }
    if(ID.Length == 0)
    this.Page.RegisterStartupScript("","<script>alert('没有选定删除项');window.location.href=window.location.href;</script>");
    else
    {
    ID = ID.Remove(ID.Length - 1,1);
    Selected_Date = Selected_Date.Remove(Selected_Date.Length-1,1);
    string sql_del = "delete from Files where ID in("+ID+")";
    string [] Arr_Id = ID.Split(',');
    for(int i=0;i<Arr_Id.Length;i++)
    {
    string strsql="select FileName from Files where id ="+Arr_Id[i];
    Con.Open();
    SqlCommand cmd =new SqlCommand(strsql,Con);
    SqlDataReader dr1 =cmd.ExecuteReader();
    if(dr1.HasRows)
    while(dr1.Read())
    {
    string File_Path = Server.MapPath("../../Files/WeeklyReport/"+dr1["FileName"].ToString().Trim());
    if(File.Exists(File_Path))
    File.Delete(File_Path);
    }
    Con.Close();
    }

    Conn.ExecuteNonQuery_Sql_alert_refurbish_self(this,sql_del,"删除成功!!!");
    }
    }
    else
    {
    this.Response.Write("<script>alert('您无权进行此操作,请与系统管理员联系!!!');</script>");
    }
    }在page_load事件中加入
    del.Attributes.Add("onClick","return confirm('确定删除记录吗?');");
      

  6.   

    clientclick="javascript:return confirm('您确定要删除吗?');"
      

  7.   

    if(window.confirm("您真的要删除吗?"){
       调用删除方法
    }
      

  8.   

    详见
    GridView实现删除时弹出确认对话框
    http://blog.csdn.net/21aspnet/archive/2007/03/25/1540301.aspx
    就你要的