我希望在日期选择器中将所有字段设置为当前日期,将开始日期设置为当前日期前两年,将结束日期设置为今天日期。但输入字段中的占位符不是当前日期
$(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);
});
关于javascript - 将当前日期作为占位符最初放置在输入字段 datepicker bootstrap 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27816152/