怎么用JS给一个文本输入框赋值为当前日期

如题所述

怎么用JS给一个文本输入框赋值为当前日期
document.getElementById("文本框ID").value=new Date();
如果你没有使用任何前端框架,且需要重手写,那么
1、如果需要设置日期的格式,就需要手动拼装日期了,如document.getElementById("文本框ID").value=(new Date().getFullYear())+"-"+(new Date().getMonth()+1)+"-"+(new Date().getDate());
2、如果要实时显示,就需要setTimeout或者seTinterval不停的赋值。
温馨提示:答案为网友推荐,仅供参考