繁体   English   中英

如何在jQuery中使用PHP变量值作为将来的范围

[英]how to use php variable value in jquery for future scope

我根据要求的URL使用了四种颜色。 这四种颜色,我需要在日历的选定日期的背景中使用和显示。 如日历中所示。 我尝试过但没有成功。

我来自具有选定选项的上一页,并且在生成的单击URL上

所选日期的CSS

.selected {
    font-weight: bold;
}

日历的标准j查询

$(document).ready(function() {
    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();

    $('#calendar').fullCalendar({
        header: {
            left: ''/*,next,today'*/,
            center: 'title',
            right: 'next'/*'month,basicWeek,basicDay'*/
        },
        editable: true,
        dayClick: function(date, allDay, jsEvent, view) {
            var myDate = new Date();
            if (date < myDate) { 
                // Do not do anything
            } else {
                console.info($.fullCalendar.formatDate( date, 'dd-MMMM-yyyy'));
                $(this).parent().parent().find('.selected').removeClass('selected');
                $(this).parent().parent().find('.click_selected').removeClass('click_selected');
                // change the day's background color just for fun
                $(this).addClass('selected');
                $(this).addClass('click_selected'); 
                $("#selectedDate").val($.fullCalendar.formatDate( date, 'dd-MMMM-yyyy'));
            }     
        }
    });
});

通过执行$(".click_selected").css({'background-color':'<?php echo $key;?>'}); 您正在为当前具有click_selected类的所有元素分配背景色

但是,您实际需要的是为click_selected类设置另一种bg颜色。

您可以在头部执行以下操作:

<style>
    .click_selected { 
        background-color:<?php echo $key;?>;
    }
</style>

您可以像这样将php值分配给javascript变量

$(document).ready(function() {
  var jVariable ="<?php echo $phpValue;?>";
});

然后,您可以在JavaScript中使用jVariable

您可以在脚本中编写所有代码

$(document).ready(function{
   <?php
        $bookingTtype = strtolower(base64_decode($get['opt']));     
        $colorArray = array("#D3542D"=>"meeting_room","#509DCE"=>"conference_room","#F3B804"=>"hot_desk","#7AB44C"=>"solo_studio"); 
        $key = array_search($bookingTtype , $colorArray);
    ?>
    $(".click_selected").css({'background-color':'<?php echo $key;?>'});
});

暂无
暂无

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

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