复制代码 代码如下:
<%@ Page Language=”C#” %>
<script runat=”server”>
protected void Page_Load(object sender, EventArgs e)
{
string myScript = @”function AlertHello() { alert(‘Hello ASP.NET'); }”;
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
“MyScript”, myScript, true);
}
</script>
复制代码 代码如下:
<html xmlns=”” >
<head><title>
Adding JavaScript
</title></head>
<body>
<form method=”post” action=”JavaScriptPage.aspx” id=”form1”>
<div>
<input type=”hidden” name=”__VIEWSTATE”
value=”/wEPDwUKMTY3NzE5MjIyMGRkiyYSRMg+bcXi9DiawYlbxndiTDo=” />
</div>
<script type=”text/javascript”>
<!--
function AlertHello() { alert(‘Hello ASP.NET'); }// -->
</script>
<div>
<input type=”submit” name=”Button1” value=”Button” onclick=”AlertHello();”
id=”Button1” />
</div>
</form>
</body>
</html>
复制代码 代码如下:
<asp:TextBox ID=”TextBox1” Runat=”server”>Hello ASP.NET</asp:TextBox>
复制代码 代码如下:
protected void Page_Load(object sender, EventArgs e)
{
string myScript = @”alert(document.forms[0][‘TextBox1'].value);”;
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), “MyScript”, myScript, true);
}
复制代码 代码如下:
protected void Page_Load(object sender, EventArgs e)
{
string myScript = @”alert(document.forms[0][‘TextBox1'].value);”;
Page.ClientScript.RegisterStartupScript(this.GetType(), “MyScript”, myScript, true);
}
复制代码 代码如下:
string myScript = “myJavaScriptCode.js”
Page.ClientScript.RegisterClientScriptInclude(“myKey”, myScript);
复制代码 代码如下:
<script src=”myJavaScriptCode.js” type=”text/javascript”></script>
新闻热点
疑难解答
图片精选