繁体   English   中英

将当前日期最初作为占位符放置在输入字段datepicker引导程序中

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

我想在日期选择器中将所有字段设置为当前日期,将开始日期设置为当前日期之前的两年,将结束日期设置为今天的日期。 但是输入字段中的占位符不是当前日期

 $(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);
});

您可以尝试以下方法:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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