如何在html文本框中显示当前日期? [英] how to display current date in html textbox?
问题描述
以下是我的尝试
< input type =textdate =trueid =txtDateOfIncorporation name =txtDateOfIncorporationvalue =01/01/0001class =Zebra_DatePicker_Icon_Wrapper hasDatepickerstyle =width:150pxheight =40size =15onload =GetDateTime()maxlength =10 >
和函数GetDatetime()是
< pre lang =xml> < script 类型 = text / javascript language = javascript >
function GetDateTime(){
var param1 = new Date();
var t2 = param1.getMonth()+ 1;
var param2 = param1.getDate();
document.getElementById('txttime')。value = param2;
}
试试这个:
< script type =text / javascriptlanguage =javascript>
函数GetDateTime(){
var param1 = new Date();
document.getElementById('txtDateOfIncorporation')。value = param1;
}
< / script>
请注意您使用的ID('txttime')错误!
在DOM准备就绪后调用该函数:
< < span class =code-leadattribute> body onload = GetDateTime(); > < / body >
检查这个
how-to-display-current-date-in-textbox-using-placeholder-in-html [ ^ ]
http://www.eborcom.com/webmaker/tutorials/rhoque/simple_scripts.html [ ^ ]
// 在这里试试
document .getElementById(' txtDateOfIncorporation')。value = param2;
见参考
http://www.w3schools.com/jsref/ tryit.asp?filename = tryjsref_text_value2 [ ^ ]
Here is what i have tried
<input type="text" date="true" id="txtDateOfIncorporation" name="txtDateOfIncorporation" value="01/01/0001" class="Zebra_DatePicker_Icon_Wrapper hasDatepicker" style="width:150px" height="40" size="15" onload="GetDateTime()" maxlength="10">
and the function GetDatetime() is
<script type="text/javascript" language="javascript">
function GetDateTime() {
var param1 = new Date();
var t2 = param1.getMonth() + 1;
var param2 = param1.getDate();
document.getElementById('txttime').value = param2;
}
Try this:
<script type="text/javascript" language="javascript"> function GetDateTime() { var param1 = new Date(); document.getElementById('txtDateOfIncorporation').value = param1; } </script>
Please notice that the id you have used ('txttime') was wrong!
Call the function after DOM is ready:
<body onload="GetDateTime();"></body>
Check this
how-to-display-current-date-in-textbox-using-placeholder-in-html[^]
http://www.eborcom.com/webmaker/tutorials/rhoque/simple_scripts.html[^]
//try here document.getElementById('txtDateOfIncorporation').value = param2;
see ref
http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_text_value2[^]
这篇关于如何在html文本框中显示当前日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!