2015-01-07 2 views
0

모든 필드에 현재 날짜로 현재 날짜와 시작 날짜를 2 년으로 설정하고 오늘 날짜로 종료 날짜를 datepicker에 설정하려고합니다. 그러나 입력 필드에 자리가 현재 날짜로 오지 않을 것은입력란에 현재 날짜를 자리 표시 자로 넣으려면 datepicker 부트 스트랩

$(document).ready(function() { 
 
\t \t /*var $datepicker = $("#datepicker"); 
 
     $datepicker.datepicker(); 
 
     $datepicker.datepicker('setDate', new Date());*/ 
 
\t \t 
 
\t \t $('input#datepicker').click(function() { 
 
\t \t // document.getElementById('datePicker').valueAsDate = new Date(); 
 
\t \t 
 
      //alert($(this).attr('id')); 
 
\t \t \t alert("you can only post interviews not more older than the last two years!!!"); 
 
      }); 
 
\t \t 
 
\t \t 
 
\t \t // adding todays date as the value to the datepickers. 
 
\t \t 
 
     var d = new Date(); 
 
     var curr_day = d.getDate(); 
 
     var curr_month = d.getMonth() + 1; //Months are zero based 
 
     var curr_year = d.getFullYear(); 
 
     var eutoday = curr_day + "-" + curr_month + "-" + curr_year; 
 
     var ustoday = curr_month + "-" + curr_day + "-" + curr_year; 
 
     $("div.datepicker input").attr('value', eutoday); 
 
     $("div.usdatepicker input").attr('value', ustoday); 
 
      //document.getElementById('datePicker').value = new Date().toDateInputValue(); 
 
     //calling the datepicker for bootstrap plugin 
 
     // https://github.com/eternicode/bootstrap-datepicker 
 
     // http://eternicode.github.io/bootstrap-datepicker/ 
 
     $('#datepicker').datepicker({ 
 
\t \t // setDate: new Date(), 
 
\t \t // datepicker('setDate', new Date()) 
 
\t \t \t //document.getElementById('datePicker').valueAsDate = new Date(); 
 
\t \t \t //document.getElementById('datePicker').value = new Date().toDateInputValue(); 
 
      autoclose: true, 
 
\t \t \t 
 
      // startDate: new Date() 
 
\t \t \t 
 
    startDate: '-24m', 
 
    // endDate: '+2d' 
 
\t endDate: new Date() 
 

 
     }); 
 
    });

답변

0

이 작업을 시도 할 수 있습니다 : -

$(document).ready(function() { 
    var date = Date(); 
    document.getElementById("yourInputID").value = date; 
}); 
1
$(document).ready(function() { 
    var date = Date(); 
    $("#yourdateinput").attr("placeholder",date); 
}); 
관련 문제