我想将Tooltip添加到保留的特定日期。我的意思是我将读取我的数据库并通过PHP获取保留日期,然后将它们传递给jQuery并向其添加Tooltip。这是我的代码。但它不起作用。 此代码仅在第一段日期添加了Tooltip:
<?php
$result = mysql_query("SELECT in_date,out_date FROM bookings");
$count = mysql_num_rows($result);
$query = $db->get_results("SELECT in_date,out_date FROM bookings");
foreach($query as $row){
$in_date=$row->in_date;
$out_date=$row->out_date;
$in_day=substr($row->in_date,-2);
$out_day=substr($row->out_date,-2);
?>
<script>
$('#dpbs').datepicker({
format: "yyyy-mm-dd",
startView:1,
weekStart: 6,
todayBtn: true,
language: "de",
daysOfWeekDisabled: "0,1,2,3,4,5,6",
datesDisabled: ['11/14/2016', '11/10/2016'],
daysOfWeekHighlighted: "6",
calendarWeeks: true,
beforeShowDay: function (date){
for (var ij = 1; ij < <?php echo json_encode($count);?>; ij++){
if (date.getMonth() == (new Date()).getMonth())
for(var i=<?php echo json_encode($in_day);?>;i<<?php echo json_encode($out_day);?>;i++){
switch (date.getDate()){
case i:
return {
tooltip: 'Example tooltip',
classes: 'active'
};
}
}
}
},
toggleActive: true
});
</script>
<?php } ?>
答案 0 :(得分:0)
添加:
.on('show',function(e) {
$('td.day.activeClass').each(function(index, element) {
var $element = $(element)
$element.attr("title", "Promo Date");
$element.data("container", "body");
$element.tooltip()
});
where&#34; activeClass&#34;是你的班级,或者只是td.day,如果你想要整天工具提示!