簡體   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