今天在禁用的输入框中显示日期

时间:2017-03-21 05:57:10

标签: html asp.net jsp date

我想问一下如何将今天的日期显示到禁用的输入日期框?

date.html:

<input id="today" type="date" disabled> 

calender.jsp:

<script>document.getElementById('today').value = moment().format('YYYY-MM-DD'); </script>

1 个答案:

答案 0 :(得分:1)

我希望这会奏效......

&#13;
&#13;
var date = document.getElementById('today');

var day = new Date();
var thisDate = day.getDate();
var thisMonth = day.getMonth()+1;
var thisYear = day.getFullYear();

if(thisDate<10){
    thisDate='0'+thisDate;
} 
if(thisMonth<10){
    thisMonth='0'+thisMonth;
} 

date.value = thisYear+'/'+thisDate+'/'+thisMonth;
&#13;
<input id="today" disabled value="21/03/2017">
&#13;
&#13;
&#13;