如何使用Javascript在标签中显示日期? [英] How to Show Date in Label using Javascript ?
本文介绍了如何使用Javascript在标签中显示日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在标签中显示日期...但未在标签中显示
代码为
Hi,
I want to show date in a label ...But it''s not showing in label
The Code is
<script type="text/javascript">
function Getdate()
{
var dt = new Date();
document.getElementById('Label1').value=dt;
}
</script>
并且html代码是
and html code is
<asp:Label ID="Label1" runat="server"></asp:Label>/>
<input id="Submit2" type="submit" value="Show Date" onclick="Getdate()" />
推荐答案
Label1
是服务器控件,因此应为
Label1
is a server control so it should be
document.getElementById(''<% =Label1.ClientID %>'').value=dt;
编辑
---------------------
阅读 Control.ClientID属性 [ ^ ]
EDIT
---------------------
Read Control.ClientID Property[^]
要在浏览器中显示,您必须使用innerHTML属性而不是value.
如果您不使用母版页,您可以这样做
To display in Browser u have to use innerHTML property instead of value.
If U r not using master page u can do like
document.getElementById('Label1').innerHTML=dt;
如果您使用母版页,您可以像
If ur using master page u can do like
document.getElementById('<% =Label1.ClientID %>').innerHTML=dt;
这篇关于如何使用Javascript在标签中显示日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文