set date in input type date

后端 未结 12 1469
广开言路
广开言路 2020-11-28 23:51

i will set today date in datepicker input type date in chrome.

$(         


        
12条回答
  •  失恋的感觉
    2020-11-28 23:55

    Fiddle link : http://jsfiddle.net/7LXPq/93/

    Two problems in this:

    1. Date control in HTML 5 accepts in the format of Year - month - day as we use in SQL
    2. If the month is 9, it needs to be set as 09 not 9 simply. So it applies for day field also.

    Please follow the fiddle link for demo:

    var now = new Date();
    
    var day = ("0" + now.getDate()).slice(-2);
    var month = ("0" + (now.getMonth() + 1)).slice(-2);
    
    var today = now.getFullYear()+"-"+(month)+"-"+(day) ;
    
    $('#datePicker').val(today);
    

提交回复
热议问题