【问题标题】:Passing string variables to a jquery code inside a php class将字符串变量传递给 php 类中的 jquery 代码
【发布时间】:2023-03-15 17:50:02
【问题描述】:

我几乎是 jquery 的新手。我有一个用于日历的 PHP 类,其中一个函数返回 jquery 代码的一部分。事实上,我想禁用日历中的特定日期,这些日期对于各种数据库查询是不同的。我可以传递变量,在 IE 的源代码中,我看到的变量是这样的:$(#datepicker1).datepicker,但是当它是静态的时,它看起来像 $("#datepicker1").datepicker。尽管在第一种样式中,变量类型是字符串,但它不理解它是一个html标签ID,并且它不会对那个标签应用方法。 这是 PHP 类中的主要函数:

function createCal($month, $day, $id)
    {

        //echo('#'.($this->datePickerID));
        $ids=("#datepicker".$id);
        echo($ids);
        return<<<html
<script>
$(function() {
    //-----------------------------------
    $($ids).datepicker({
        beforeShowDay: function(date) {
            //alert(date.getDate());
            if (date.getDay()==5 ||( date.getMonth()==$month && date.getDate() == $day))
                return [false, '', 'weekends'];
            return [true];
        }
    });


});

这是来自 IE 的源代码

<script>
$(function() {
    //-----------------------------------

    $(#datepicker1).datepicker({
        beforeShowDay: function(date) {
            //alert(date.getDate());
            if (date.getDay()==5 ||( date.getMonth()==0 && date.getDate() == 26))
                return [false, '', 'weekends'];
            return [true];
        }
    });


});
</script>
<p class='ui-widget-content'>

    date:
    <input type="text" id="datepicker1" />
</p>

【问题讨论】:

  • 使用 JSON 传递数据

标签: php jquery class variables


【解决方案1】:

您需要在 ID 周围加上引号:

$('$ids').datepicker({

【讨论】:

  • 谢谢,解决了,但它是一个变量,是不是一个JS语法把一个字符串变量再放在引号里?
  • PHP 值没有引号,所以你必须添加它们。
猜你喜欢
  • 2018-03-05
  • 2013-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-30
  • 2016-01-17
相关资源
最近更新 更多