如何在InOut窗体字段中将当前日期作为值插入?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (60)

我能够以我想要的格式获得Java的当前日期,并且实际上希望它在输入字段中显示为文本值。我不想使用type=“date”来选择。有什么标题,或者如何将当前日期作为一个值插入到输入字段中?我不介意php是否实现。

 <input type="text" value='<span id="date"></span>'>

Java脚本

  var months = ["January", "February", "March", "April", "May", "June",    
  "July", "August", "September", "October", "November", "December"];
  var n = new Date();
  var y = n.getFullYear();
  var m = n.getMonth();
  var d = n.getDate();
  document.getElementById("datea").innerHTML = d + " " + months[m] + " " +    
   y;
提问于
用户回答回答于

你犯了几个错误。

var months = ["January", "February", "March", "April", "May", "June",
  "July", "August", "September", "October", "November", "December"
];
var n = new Date();
var y = n.getFullYear();
var m = n.getMonth();
var d = n.getDate();
document.getElementById("date").value = d + " " + months[m] + " " + y;
<input type="text" id="date">

扫码关注云+社区

领取腾讯云代金券