2015-07-28 136 views
-1

我遇到問題。我想將輸入字段中的日期更改爲當前日期。這裏是我的代碼:在輸入類型日期中更改日期HTML

<input type="date" id="datum currentdate"> 
$(document).ready(function() { 
    var now = new Date(); 
    var day = ("0" + now.getDate()).slice(-2); 
    var month = ("0" + (now.getMonth() + 1)).slice(-2); 
    var today = now.getFullYear()+"-"+(month)+"-"+(day) ; 
    $('#currentdate').val(today); 
}); 

但是,這是行不通的。我已經包含了jQuery。有誰知道這個問題的解決方案?

+1

什麼意思 「但是,這是行不通的。」? – Jens

+0

它包括tt.mm.jjjj。 – Micha

+0

這是類型=「日期」 – Micha

回答

0

您輸入字段的ID必須是currentdate也不datum currentdate

<input type="date" id="currentdate"> 
+0

但我需要其他ID在我的代碼中的其他東西.... – Micha

+0

@Micha然後你可以改變字段的ID和在你的jQuery。但不要在ID中使用空格。 – Jens

+0

現在起作用了。 :D我只是用一個沒有身份證明的班級做的。 – Micha

0
<input id="currentdate" name="date"> 

<script type="text/javascript"> 
    document.getElementById('currentdate').value = Date(); 
</script> 
+1

我認爲增加一些解釋會使答案更好。謝謝 – dav

相關問題