在jquery中使用日期选择器,今天显示

时间:2013-07-24 07:11:03

标签: javascript html5 jquery-ui-datepicker

我希望datepicker选择currentdate / today并显示它而不是'dyyy'而且我希望今天之前的日期禁用选择,请帮忙!

    $(document).ready(function () {
    $("#button_id").click(function () {
        $('<div/>', {
            id: "div_id"
        }).append($('<input>', {
            type: "date",
            name: "someDate",
            class: "date_id"
        })).appendTo("#static_div");
        $(".date_id").datepicker({
            //i want the datepicker to select the currentdate/today and display it instead of'dd----yyyy'and moreover i wanted the date before today to be disabled from selection
        });
    });
});

这是我小提琴的链接:

http://jsfiddle.net/L4reds/73pEN/1/

3 个答案:

答案 0 :(得分:2)

$(document).ready(function () {
    $("#button_id").click(function () {
        var div = $('<div/>', {id: "div_id"}),
            inp = $('<input>', {type: "text",name: "someDate",id: "date_id"});

        div.append(inp).appendTo("#static_div");
        inp.datepicker({
            minDate: 0
        }).datepicker('setDate', new Date());
    });
});

FIDDLE

答案 1 :(得分:0)

使用 minDate maxDate 选项隐藏上一个日期see this

 $(function() {
    $( "#datepicker" ).datepicker({ minDate: -20, maxDate: "+1M +10D" });
 });

格式选项set using this option

答案 2 :(得分:0)

要在当天之前停用日期:

 $("#date_id").datepicker({
     minDate: 0
 });

阅读文档:http://api.jqueryui.com/datepicker/#option-minDate