更改日期输入日期HTML

时间:2015-07-28 07:48:13

标签: javascript jquery html css

我有问题。我想将输入字段中的日期更改为当前日期。这是我的代码:

<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。有没有人知道这个问题的解决方案?

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

输入字段的ID必须为currentdatedatum currentdate

<input type="date" id="currentdate">
相关问题