JS如何获取label的值?
页面A.aspx有一个label
<asp:Label ID="Label1" runat="server" Text="" ></asp:Label>
A页面的后台对label赋值
if (!IsPostBack)
{
Label1.Text=动态参数
}
JS:
var lbl7=document.getElementById("Label1").innerHTML;
alert(lbl7);
现在的问题是JS无法获得label1的值
------解决方案--------------------
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script runat="server" language="javascript" type="text/javascript">
function test()
{
var lbl7=document.getElementById("Label2").innerText;
alert(lbl7);
}
</script>
</head>
<body onload="test()">
<div>
<label id="Label1">aaaaaa</label>
<asp:Label ID="Label2" runat="server" Text="bbb" >bbb</asp:Label>
</div>
</body>
</html>