我想将当前日期添加到隐藏的HTML标记中,以便可以将其发送到服务器:
<input type="hidden" id="DATE" name="DATE" value="WOULD_LIKE_TO_ADD_DATE_HERE">
如何将格式化的日期添加到VALUE属性?
const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; let dateObj = new Date(); let month = monthNames[dateObj.getMonth()]; let day = String(dateObj.getDate()).padStart(2, '0'); let year = dateObj.getFullYear(); let output = month + '\n'+ day + ',' + year; document.querySelector('.date').textContent = output;