一个很好的例子,四种方法来激发JS。
html:
<%@ Page language="c#" Codebehind="VC1.aspx.cs" AutoEventWireup="false" Inherits="WebApplicationCSharp.form1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Click 事件使用示范</title>
<meta content="True" name="vs_showGrid">
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<script language="JavaScript">
function sayhello()
{
alert("大家好/n/n欢迎光临");
}
</script>
<form id="form1" method="post" runat="server">
<INPUT id="btnSubmit1" style="FONT-SIZE: 12pt; Z-INDEX: 101; LEFT: 26px; POSITION: absolute; TOP: 21px" type="submit" value="请按我" οnclick="sayhello()">
<INPUT id="btnSubmit2" style="FONT-SIZE: 12pt; Z-INDEX: 102; LEFT: 26px; POSITION: absolute; TOP: 87px" type="submit" value="请按我" οnclick="sayhello()" runat="server" NAME="btnSubmit2">
<asp:button id="btnSubmit3" style="Z-INDEX: 103; LEFT: 26px; POSITION: absolute; TOP: 153px" runat="server" Text="请按我" Font-Size="12pt"></asp:button>
<INPUT id="btnSubmit4" style="FONT-SIZE: 12pt; Z-INDEX: 104; LEFT: 25px; POSITION: absolute; TOP: 223px" type="button" value="请按我" οnclick="sayhello();" runat="server" NAME="btnSubmit4"></form>
</body>
</HTML>
cs:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebApplicationCSharp
{
/// <summary>
/// VC1 的摘要描述。
/// </summary>
public class form1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnSubmit3;
protected System.Web.UI.WebControls.DropDownList ColorDropList;
protected System.Web.UI.HtmlControls.HtmlInputButton btnSubmit4;
protected System.Web.UI.HtmlControls.HtmlInputButton btnSubmit2;
private void Page_Load(object sender, System.EventArgs e)
{
btnSubmit3.Attributes.Add("onclick", "sayhello()");
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 此呼叫为 ASP.NET Web Form 设计工具的必要项。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 此为设计工具支持所必需的方法 - 请勿使用程式码编辑器修改
/// 这个方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnSubmit3.Click += new System.EventHandler(this.btnSubmit3_Click);
this.btnSubmit2.ServerClick += new System.EventHandler(this.btnSubmit2_ServerClick);
this.btnSubmit4.ServerClick += new System.EventHandler(this.btnSubmit4_ServerClick);
this.ID = "form1";
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnSubmit2_ServerClick(object sender, System.EventArgs e)
{
btnSubmit2.Value = DateTime.Now.ToString();
}
private void btnSubmit3_Click(object sender, System.EventArgs e)
{
btnSubmit3.Text = DateTime.Now.ToString();
}
private void btnSubmit4_ServerClick(object sender, System.EventArgs e)
{
btnSubmit4.Value = DateTime.Now.ToString();
}
}
}
服务端的Button触发js函数
最新推荐文章于 2024-08-27 13:38:21 发布