在 Javscript 函数中,我为标签赋值。已分配值,但标签属性正在更改为默认值。
document.getElementById("Label1").innerText = dispTime;
dispTime是 javascript 函数中的某个值。
<asp:Label ID="Label1" runat="server" ToolTip="Current Time" ForeColor="BlueViolet" BorderStyle="Ridge" BackColor="ButtonHighlight"></asp:Label>
这是我的标签的定义方式,但在页面加载后标签属性更改为默认值
我的页面加载
ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript:InIt();", true);
我的 javascript 部分
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="head1" runat="server">
<title>Time</title>
<script type="text/javascript">
function InIt() {
var dateTime = new Date();
var hours = dateTime.getHours();
var minutes = dateTime.getMinutes();
var seconds = dateTime.getSeconds();
var day;
if (hours < 11) {
day = "AM";
}
else {
day = "PM";
}
if (minutes < 10) {
minutes = "0" + minutes;
}
if (seconds < 10) {
seconds = "0" + seconds;
}
var dispTime = document.getElementById("time").innerHTML = hours + ":" + minutes + ":" + seconds + " " + day;
setTimeout("InIt()", 1000);
var updatetime = document.getElementById("Label1");
updatetime.innerText = dispTime;
}
InIt();
</script>
<form id="form1" runat="server">
<div id="time" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Label ID="Label1" runat="server" ToolTip="Current Time" style="background-color:ButtonHighlight; border-style:ridge;"></asp:Label>
</div>
</form>