日期:2014-05-18 浏览次数:20495 次
function writeString() { document.getElementById("Label1").Value="Hello World"; }
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!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>无标题页</title> <script type="text/javascript" src="JS/test.js"></script> </head> <body onload="writeString()"> <form id="form1" runat="server"> <asp:Label ID="Label1" runat="server"></asp:Label> <div> </div> </form> </body>
function writeString() { document.getElementById("Label1").innerHTML="Hello World"; }
------解决方案--------------------
<body onload="writeString()">
顺序不对 调用函数的时候label还没有创建啦
------解决方案--------------------
你这样写,那控件不能是服务器控件的,再说了服务器控件也没VALUE这个属性
------解决方案--------------------
考虑到母版页等的情况,最好的以后习惯用:
document.getElementById('<%= Label1.ClientID %>').innerText = "Hello World";
这种写法。
------解决方案--------------------