0

我正在努力获得一个看起来和行为与分配给现场输入字段的内联日期选择器完全相同的年历。所以我创建了这个块

<div class="box_content">
   <div class="yearCal" id="cal2"><!-- this will receive the calendar --></div>
 </div>

并将 datepicker 对象分配给 id 为“cal2”的元素。这使我的日历小部件显示 12 个月。每个 td 元素如下所示:

<td about="I receive class 'free' or 'booked' from 'BeforeShowDay' handler">
   <a about="I am the element catching the click and need the parent class"></a>
</td>

我使用此代码测试配置了 datepicker 的 onSelect 函数

onSelect: function(dateText, inst) { 
   console.debug( jQuery(this).parent().attr('class') ); 
}

但是当我点击一个日历日时,我会得到 id 'box_content'。无论我尝试什么,我都没有得到父母的元素。但是我需要得到它,因为当小部件被渲染时,每个 td 元素都会获得一个“免费”或“预订”类,并且根据它的类,我必须执行一些数据库操作。

你能告诉我怎么做吗?

4

1 回答 1

0

我看不到你的日期选择器在哪里,但是,假设你有这样的东西:

<td about="I receive the class 'free' or 'booked' from 'BeforeShowDay' event">
   Date: <input type="text" id="datepicker" about="input receiving the onSelect event">
</td>

您可以像这样访问包含 datepicker 的 td 类(在 onSelect 事件上):

<script type="text/javascript">
  $('#datepicker').datepicker({
     onSelect: function(dateText, inst) {
        //dosomething
        var tdclass = $(this).parent().attr('class');  
        //dosomethingelse
     }
  });
</script>
于 2011-10-06T17:47:24.633 回答