原文发布时间为:2008-10-31 —— 来源于本人的百度文章 [由搬家工具导入]

我想这样,点击一个按钮,然后程序执行一半的时候,跳出一个选择“是否继续执行?”,这样的效果,如果我点击 是,它就继续执行,如果点击 否 ,结束。。。
基本思想:用一个按钮(按钮的width属性设成0,这样就成为了一个隐形按钮),然后判断confirm的值来确定是否用getElementById的方法点击那个“隐形按钮”。。。

主要语句:

ClientScript.RegisterStartupScript(Page.GetType(), "", " <SCRIPT>if(confirm('要输出world么?')) document.getElementById('Unnamed1').click(); </SCRIPT>");

前台 code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head /> </form> </body> </html>



后台 code
using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partial class Default4 : System.Web.UI.Page{ string str = "hello"; protected void Page_Load(object sender, EventArgs e) { } protected void Unnamed1_Click(object sender, EventArgs e) { Response.Write(str+" world!"); } protected void Button1_Click(object sender, EventArgs e) { Response.Write(str); ClientScript.RegisterStartupScript(Page.GetType(), "", " <SCRIPT>if(confirm('要输出world么?')) document.getElementById('Unnamed1').click(); </SCRIPT>"); //应该写成以上这句,写下面这句将找不到button1 //Response.Write(" <SCRIPT>if(confirm('要输出world么?')) document.getElementById('Unnamed1').click(); </SCRIPT>"); } }


相关文章:

  • 2022-12-23
  • 2021-09-20
  • 2021-11-03
  • 2022-12-23
  • 2022-12-23
  • 2021-05-26
  • 2022-12-23
  • 2021-07-14
猜你喜欢
  • 2022-12-23
  • 2021-05-21
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2021-09-08
  • 2022-01-17
相关资源
相似解决方案