重置jQuery ui日期选择器

时间:2014-08-26 00:55:13

标签: jquery-ui-datepicker

当用户点击重置按钮时,它会清除输入框,但不会重置为今天的日期。相反,它会禁用我不想要的日期范围。我如何获得它以便所有日期再次出现?就像刚开始一样。

我试过这样做。清除数据然后刷新它但它仍然不起作用。 $(“#to”)。datepicker('setDate',null); $(“#to”)。datepicker(“refresh”);

这是我的代码:

http://plnkr.co/edit/seX4mgOGAeKDZRGTJCWx?p=preview

OR

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Select a Date Range</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">

<script>
$(function() {
    $( "#from" ).datepicker({
       numberOfMonths: 2,
       minDate: 0,
       onClose: function( selectedDate ) {
          $( "#to" ).datepicker( "option", "minDate", selectedDate );
       }
    });

    $( "#to" ).datepicker({
       numberOfMonths: 2,
       onClose: function( selectedDate ) {
          $( "#from" ).datepicker( "option", "maxDate", selectedDate );
       }
    });
});

function clearData(){
   $( "#to").datepicker('setDate', null);
   $( "#from").datepicker('setDate', null);
   $( "#to" ).datepicker( "refresh" );
   $( "#from" ).datepicker( "refresh" );
}
</script>
</head>

<body>
Departure <input type="text" id="from" name="from">
Arrival <input type="text" id="to" name="to"><br><br> 

<button type="button" onclick="clearData()">Reset</button>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

在表单和日期Id属性上调用jQuery更改方法。 $(“#to”)。change();  $(“#from”)。change();

相关问题