开发者

how i can set or change the default date in jQuery UI datepicker?

开发者 https://www.devze.com 2023-03-01 12:39 出处:网络
in a dynamic form when content come from server through ajax request i want to create a new datepicker based on existing textbox who already intialize when page load.

in a dynamic form when content come from server through ajax request i want to create a new datepicker based on existing textbox who already intialize when page load.

actually ajax request return data and i show the form with fillling the default data.

 $("#llogin").datepicker({ disabled: true });
    $("#flogin").datepicker({ disabled: true });

this code i run on document ready and later i change them through

   $("#llogin").datepicker("option", "defaultDate", ParseJSONDate(fdate));
        $("#flogin").datepicke开发者_如何学JAVAr("option", "defaultDate", ParseJSONDate(ldate));

now i see that two date who i not want. i want to set the date who come from ajax request.

how i can set the default date without setting a another date. i just want to change the date from the date who i got from ajax request.

can someone show me code to do that


Use its defaultDate property. Just set it to a JavaScript date object with the date you want.


<input type="text" id="llogin" name="llogin"/>

and

$("#llogin").datepicker({ disabled: false});

var myDate = new Date();
var prettyDate =(myDate.getMonth()+1) + '/' + myDate.getDate() + '/' +
        myDate.getFullYear();
$("#llogin").val(prettyDate);

In above code I am assigning the current date to the datepicker... Instead of that you can assign your json returned date...


Here is an example of using jquery's default date in the datepicker:

var fromDate = new Date('5-6-2015');

jQuery(".divFromDate").datepicker({
    minDate: new Date('1/1/2000'),
    maxDate: '-8',
    defaultDate: fromDate,
    ...
0

精彩评论

暂无评论...
验证码 换一张
取 消