本文介绍了如何在html文本框中显示当前日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 以下是我的尝试 < input type =textdate =trueid =txtDateOfIncorporation name =txtDateOfIncorporationvalue =01/01/0001class =Zebra_DatePicker_Icon_Wrapper hasDatepickerstyle =width:150pxheight =40size =15onload =GetDateTime()maxlength =10 > 和函数GetDatetime()是 < 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准备就绪后调用该函数: < 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 thishow-to-display-current-date-in-textbox-using-placeholder-in-html[^]http://www.eborcom.com/webmaker/tutorials/rhoque/simple_scripts.html[^]//try heredocument.getElementById('txtDateOfIncorporation').value = param2;see refhttp://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_text_value2[^] 这篇关于如何在html文本框中显示当前日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-25 02:24