jQuery UI中的Defautl值

时间:2015-09-23 12:52:27

标签: jquery-ui

当我激活jQuery UI时,我希望有一个默认值,包括今天的'to'和'from',以及我应该如何根据下面的代码进行操作?

'http://jsbin.com/ceyuhudajo/edit?html,output'

  $(function() {
    $( "#from").datepicker({
      showWeek: true,
      firstDay: 1,
      defaultDate: "+1w",
      changeMonth: true,
      numberOfMonths: 2,
      dateFormat: "yy-mm-dd",
      onClose: function( selectedDate ) {
        $( "#to" ).datepicker( "option", "minDate", selectedDate );
      }
    });
    

    $( "#to" ).datepicker({
      showWeek: true,
      firstDay: 1,      
      defaultDate: "+1w",
      changeMonth: true,
      numberOfMonths: 2,
      dateFormat: "yy-mm-dd",      
      onClose: function( selectedDate ) {
        $( "#from" ).datepicker( "option", "maxDate", selectedDate );
      }
    });
  });
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">


  
<label for="from">From</label>
<input type="text" id="from" name="from">
<label for="to">to</label>
<input type="text" id="to" name="to">

谢谢!

1 个答案:

答案 0 :(得分:0)

你应该删除: defaultDate:“+ 1w” 它将默认日期设置为提前一周。