简体   繁体   中英

to place current date as placeholder initially in the input field datepicker bootstrap

I want to have all the fields set date as current date, start date as two years before the current date and end date as the today date, in the datepicker. But the placeholder in input field not coming as the current date

 $(document).ready(function() { /*var $datepicker = $( "#datepicker" ); $datepicker.datepicker(); $datepicker.datepicker('setDate', new Date());*/ $('input#datepicker').click(function() { // document.getElementById('datePicker').valueAsDate = new Date(); //alert($(this).attr('id')); alert("you can only post interviews not more older than the last two years!!!"); }); // adding todays date as the value to the datepickers. 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({ // setDate: new Date(), // datepicker('setDate', new Date()) //document.getElementById('datePicker').valueAsDate = new Date(); //document.getElementById('datePicker').value = new Date().toDateInputValue(); autoclose: true, // startDate: new Date() startDate: '-24m', // endDate: '+2d' endDate: new Date() }); }); 

$( document ).ready(function() {
    var date = Date();
   $("#yourdateinput").attr("placeholder",date);
});

You can try this:-

$( document ).ready(function() {
    var date = Date();
    document.getElementById("yourInputID").value = date;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM