donglang7236 2018-06-01 08:10
浏览 49

Php语法。 如何在onclick事件中正确获取此代码?

I have two <a></a> tags which holds the onclick event and has PHP code in it. Obviously I need them to work. What those links do - switch between months. Here are the links.

<a href="javascript:void(0);" onclick="getCalendar('calendar_div','<?php echo date("Y",strtotime($date.' - 1 Month')); ?>','<?php echo date("m",strtotime($date.' - 1 Month')); ?>');"><span class="glyphicon glyphicon-chevron-left"></span></a>
<select name="month_dropdown" class="month_dropdown dropdown"><?php echo $this->getAllMonths($dateMonth); ?></select>
<select name="year_dropdown" class="year_dropdown dropdown"><?php echo $this->getYearList($dateYear); ?></select>
<a href="javascript:void(0);" onclick="getCalendar('calendar_div','<?php echo date("Y",strtotime($date.' + 1 Month')); ?>','<?php echo date("m",strtotime($date.' + 1 Month')); ?>');"><span class="glyphicon glyphicon-chevron-right"></span></a>

As you can see I have the $this-> pointer in <select></select> tags which allows it to be in use because I am using classes and there has to be the pointer there I assume. So how do I get the tags to work? When I add the $this-> pointer to the onclick event in front of getCalendar the PHP code just breaks down.

Do I have to use some other method in order to achieve what I am after?

  • 写回答

2条回答 默认 最新

  • douji6461 2018-06-01 08:21
    关注

    The pseudo-variable $this is available when a method is called from within an object context. If your code is not part of class definition, you must create object first:

    $obj = new Class();

    Then use class methods with:

    $obj->getAllMonths($dateMonth);.

    You can read this about PHP classes.

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类