protected void Page_Load(object sender, EventArgs e)
{
string myScript = @"alert(document.forms[0]['Label1'].value;)"; Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", myScript, true);
}<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!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 runat="server">
<title id="Title1" runat="server">无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label">aaa</asp:Label>
</div>
</form>
</body>
</html>------------------------------------------------------------------
执行后的HTML
<!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><title>
无标题页
</title></head>
<body>
<form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTcyMTYyMjM5NmRkZdqwnR4d9teWOEPkUQTLVxGRQps=" />
</div> <div>
<span id="Label1">aaa</span>
<input type="submit" name="Button1" value="Button" id="Button1" /></div>
<div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgL5mKTeAgKM54rGBvLIeDMJhguFT2LbZlAJJbn9It8H" />
</div><script type="text/javascript">
<!--
alert(document.forms[0]['Label1'].value;)// --><!--行22,字符40-->
</script>
</form>
</body>
</html>
行22,字符40错误:缺少')'
{
string myScript = @"alert(document.forms[0]['Label1'].value;)"; Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", myScript, true);
}<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!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 runat="server">
<title id="Title1" runat="server">无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label">aaa</asp:Label>
</div>
</form>
</body>
</html>------------------------------------------------------------------
执行后的HTML
<!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><title>
无标题页
</title></head>
<body>
<form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTcyMTYyMjM5NmRkZdqwnR4d9teWOEPkUQTLVxGRQps=" />
</div> <div>
<span id="Label1">aaa</span>
<input type="submit" name="Button1" value="Button" id="Button1" /></div>
<div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgL5mKTeAgKM54rGBvLIeDMJhguFT2LbZlAJJbn9It8H" />
</div><script type="text/javascript">
<!--
alert(document.forms[0]['Label1'].value;)// --><!--行22,字符40-->
</script>
</form>
</body>
</html>
行22,字符40错误:缺少')'
解决方案 »
- 用css 来冻结gridview 表头
- 关于asp.net (c#)叶面单据和报表套打的问题
- 求解!Cache与Application的性能
- 使用asp.net做网页,编译后文件大概有多大?
- [馨郁星愿]关于datalist绑定图片的问题,希望哪个有空进来看看
- 母版页中的分页
- 如何用IFRAME写一个框架有,top.aspx,left.aspx,right.aspx呢?
- 散分讨论窗体验证(Form authentication)
- 请教在DataGrid1_ItemCommand事件中,对BoundColumn列的访问代码?
- aspx/asp页面间传递参数为什么带有中文不行?
- GirdView问题?
- GridView 索引超出范围 的问题
alert(document.getElementById("Label1").innerHTML);
=================================================================
string myScript = @"alert(document.forms[0]['Label1'].value);";