gpt4 book ai didi

javascript - 无法从 asp :Label after changing it with javascript 获取文本属性

转载 作者:行者123 更新时间:2023-11-30 16:53:28 26 4
gpt4 key购买 nike

我有这个 javascript 函数:

<script type="text/javascript">
function DisplayTime() {
var d = new Date();
document.getElementById('<%=Label1.ClientID %>').innerHTML = d.localeFormat("yyyy-mm-dd HH:mm:ss");
}
</script>

我有这个标签:

<asp:Label ID="Label1" runat="server" Text ="labelText" ></asp:Label>

在 CodeBehind 中我这样做:

Page.ClientScript.RegisterStartupScript(GetType(), "DisplayTime", "DisplayTime();", true);
string text = Label1.Text;

DisplayTime() 函数工作正常。

我运行时在浏览器中显示的Label1文本是: 2015-21-08 17:21:36 <- 这很好。

但是当我尝试从 CodeBehind 读取 Label1 的文本属性时,我得到了原始文本值: “标签文本”

有人知道为什么吗?

问候鲁本克

最佳答案

我在这里找到了解决方案: Retrieve Client's Today's Date using ASP.NET

关于javascript - 无法从 asp :Label after changing it with javascript 获取文本属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30134341/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com