如何使用php调用当前年份的onclick函数

时间:2017-01-31 12:13:58

标签: php

在下面的代码中,我需要在2017年更新当前年份如何将当前年份添加到该地方

我发现$curYear = date('Y');显示当前年份。但我不知道如何在那个地方调用特定变量

请有人帮我解决这个问题。我是php的新手。提前谢谢....

 <td  align="left" width="30%">
    <input type="text" name="ToDate" id="ToDate" size="18" readonly="readonly" />
    <a href="javascript:void(0);" onClick="setYears(1947, 2017); showCalender(this, 'ToDate');">
    <img src="../calendar/calender.png"></a>
    </td>

2 个答案:

答案 0 :(得分:3)

如果您使用的文件是.php文件,则可以使用php echo替换日期。

<td  align="left" width="30%">
<input type="text" name="ToDate" id="ToDate" size="18" readonly="readonly" />
<a href="javascript:void(0);" onClick="setYears(1947, <?php echo date('Y'); ?>); showCalender(this, 'ToDate');">
<img src="../calendar/calender.png"></a>
</td>

这将作为您的示例呈现给客户。

答案 1 :(得分:2)

试试这个

  $year = date('Y'); // or you want static then $year = 2017; 
   <a href="javascript:void(0);" onClick="setYears(1947, <?php echo $year; ?>); showCalender(this, 'ToDate');">