2016-10-04 57 views
-1

在此圖像中,當我從下拉列表中選擇值並選擇日期然後顯示容器,然後當我從表數據中選擇行然後cont和sumdata div顯示現在我想要當我選擇再從日期選擇器日期,然後想隱藏的所有div ...當點擊搜索後要顯示容器隱藏div日期時間選擇器單擊

image

<script type="text/javascript"> 

     $(function() { 

      var currentYear = (new Date).getFullYear(); 
      var currentMonth = (new Date).getMonth(); 
      var currentDay = (new Date).getDate(); 
      $('#fromdate').datepicker({ 
       showSecond: false, 
       timeFormat: 'HH:mm', 
       minDate: new Date((currentYear - 2), 12, 1), 
       //minDate: 0, 
       dateFormat: 'yy-mm-dd', 
       maxDate: new Date(currentYear, currentMonth, currentDay), 
       //maxDate: new Date((currentYear + 1), 12, 1), 
       onSelect: function (selectedDate) { 

        // Start Date 
        var startDate = $(this).datepicker('getDate'); 

        //startDate.SetHours(0); 
        //startDate.setMinutes(0); 
        //startDate.setSeconds(0); 

        $('#todate').datepicker('option', 'minDate', startDate); 
        $('#todate').datepicker('setDate', startDate); 

        // End Date 
        var enddate = $(this).datepicker('getDate'); 
        enddate.setDate(enddate.getDate() + 60); 
        // endDate.setMonth(endDate.getMonth() + 2); 
        $('#todate').datetimepicker('option', 'maxDate', enddate); 
       } 
      }); 



     $('#todate').datepicker({ 
      showSecond: false, 
      timeFormat: 'HH:mm', 
      minDate: new Date((currentYear - 2), 12, 1), 
      minDate: 0, 
      dateFormat: 'yy-mm-dd', 
      maxDate: '+30', 
      //maxDate: endDate.setMonth(endDate.getMonth() + 2) 


     }); 

     $('#fromdate').on('click', function() { 
       $("#tabledata").hide(); 
      $('#container').hide(); 
      $("#cont").hide(); 
      $("#sumdata").hide(); 
      $("#sum").hide(); 
     }); 

     $("#todate").datepicker({ 
      onSelect: function (dateText) { 
       $("#tabledata").hide(); 
       $('#container').hide(); 
       $("#cont").hide(); 
       $("#sumdata").hide(); 
       $("#sum").hide(); 
      } 
     }); 

    }); 
    </script> 
+0

你可以用'日期選擇器的onselect'事件。 –

+0

我在成功後或在其他情況下如何做? @Loading .. –

回答

1

使用onselect選項來執行任何JavaScript轉換

例如: -

$(".datepicker").datepicker({ 
    onSelect: function(dateText) { 
    // hide your divs 
    $('.mydivs').hide(); 
    } 
}); 

http://api.jqueryui.com/datepicker/#option-onSelect

工作小提琴:

https://jsfiddle.net/7dy0wduc/

+0

我在成功後做這個或在其他地方? –

+0

@rebmaamber - 它不是'ajax'事件。這是一個'datepicker'選項。你應該把它放在你的'datepicker'創建語句中。 – Ted

+0

和我這樣做,但這不工作..我寫什麼,而不是datetext? –