2013-07-24 64 views
0

我希望datepicker选择currentdate/today并显示它而不是'dd-yyyy',而且我希望今天之前的日期不能选择,请帮帮我!在jquery中使用日期选择器,今天显示

$(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/

+0

你不能有相同的ID不止一个对象,使用而不是css类。 :) –

+0

你想让它选择一天,同时给你一个选择?我不理解你的问题。 – RRikesh

回答

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

+0

+1。真棒回答:) – RRikesh

+0

正是我想要的..非常感谢你.... 8分钟后我会接受这个答案..:D:D:D – L4reds

0

使用的minDate的maxDate选项隐藏previouse日期see this

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

格式选项set using this option

相关问题