简体   繁体   English

jQuery datepicker - 在init之后更改.ui-datepicker-calendar的显示

[英]jQuery datepicker - change display of .ui-datepicker-calendar after init

How can I change the css display attribute of the ui-datepicker-calendar class after the datepicker has already been initialized? 在初始化datepicker之后,如何更改ui-datepicker-calendar类的css display属性? I have a html form with a selectable checkbox from which I want to toggle the display of this table. 我有一个带有可选复选框的html表单,我想从中切换此表的显示。 I've tried the following: 我尝试过以下方法:

HTML sample: HTML示例:

 <div class="row">
  <div class="adddescr"><label for="date">Zeitraum:</label></div>
  <div class="addinput" id="date"><input type="text" id="datefrom" name="datefrom" class="date" /> - <input type="text" id="dateto" name="dateto" class="date" /></div>
 </div>
 <div class="row">
  <div class="addinput"><label><input type="checkbox" id="dateplanedcheck" /> grobe Planung</label></div>
 </div>

JS first approach: JS第一种方法:

 <script>
  $(document).ready(function() {
   $("#datefrom, #dateto").datepicker({ dateFormat: "dd.mm.yy",

   [...]

    beforeShow: function(input, inst) {
     if ($("#dateplanedcheck").is(':checked')) {
      $(".ui-datepicker-calendar").css("display", "none");
    }}
   });

   [...]

  });
 <script>

The beforeShow is called, but the calender is still displayed. 调用beforeShow,但仍然显示日历。

JS second approach: JS第二种方法:

 <script>
  $(document).ready(function() {

  [....]

   $("#dateplanedcheck").change(function() {
    if ($(this).is(':checked')) {
      $(".ui-datepicker-calendar").css("display", "none");
    }
   });
  });
 </script>

What am I missing? 我错过了什么? Does this even work with jQuery? 这甚至适用于jQuery吗? Thanks in advance! 提前致谢!

So you want to NOT show the calendar if the checkbox is checked? 因此,如果选中复选框,您是否希望不显示日历?

Just return false; 只是return false; in the beforeShow. 在beforeShow中。

$("#datefrom, #dateto").datepicker({
    dateFormat: "dd.mm.yy",
    beforeShow: function(input, inst) {
        if ($("#dateplanedcheck").prop('checked')) {
            return false;
           }

    }
});

http://jsfiddle.net/JzbPD/ http://jsfiddle.net/JzbPD/

Answer: 回答:

Still displaying the calendar but making it invisible: 仍然显示日历但使其不可见:

BeforeShow can't access the ui-datepicker-calendar on the table because it hasn't been rendered yet. BeforeShow无法访问表上的ui-datepicker-calendar,因为它尚未呈现。 Apply a class like $(inst.dpDiv).addClass('calendar-off') and then have the style .calendar-off table.ui-datepicker-calendar { display none; } 应用类似$(inst.dpDiv).addClass('calendar-off') ,然后使用样式.calendar-off table.ui-datepicker-calendar { display none; } .calendar-off table.ui-datepicker-calendar { display none; } like this: http://jsfiddle.net/JzbPD/4 .calendar-off table.ui-datepicker-calendar { display none; }这样的: http://jsfiddle.net/JzbPD/4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM