按下PHP按钮后,页面上升
我使用了一个使用PHP的互联网日历。它有“下一步”和“上一步”这样的按钮,当我按下其中一个按钮时,它会将我带到页面顶部。我怎样才能解决这个问题 这是我创建日历的代码:按下PHP按钮后,页面上升,php,calendar,Php,Calendar,我使用了一个使用PHP的互联网日历。它有“下一步”和“上一步”这样的按钮,当我按下其中一个按钮时,它会将我带到页面顶部。我怎样才能解决这个问题 这是我创建日历的代码: return '<div class="header">'. '<a class="prev" href="'.$this->naviHref.'? month='.sprintf('%02d',$preMonth).'&yea
return
'<div class="header">'.
'<a class="prev" href="'.$this->naviHref.'?
month='.sprintf('%02d',$preMonth).'&year='.$preYear.'">Prev</a>'.
'<span class="title">'.date('Y M',strtotime($this->currentYear.'-'.$this->currentMonth.'-1')).'</span>'.
'<a class="next" href="'.$this->naviHref.'?month='.sprintf("%02d", $nextMonth).'&year='.$nextYear.'">Next</a>'.
'</div>';
}
返回
''.
''.
''.date('Y M',strottime($this->currentYear.'-'.$this->currentMonth.'-1'))'。
''.
'';
}
这里是calendar.php
我认为问题不在于更新的代码,而在于将
$\u服务器['PHP\u SELF']
分配给构造函数中的naviehref
public function __construct() {
$this->naviHref = htmlentities($_SERVER['PHP_SELF']);
}
阅读脚本中的$\u SERVER['PHP\u SELF']
值,在脚本中创建日历
实例,并将该值作为参数传递给日历
构造函数。其中它将被分配给naviehref
另外,show()
中的前两行是引起注意的内容
$year == null;
$month == null;
换成
$year = null;
$month = null;
编辑:
要使用日历组件,必须创建其实例,即Calendar
类型的对象,如下所示:
$calendar = new Calendar();
public function __construct($naviHref) {
$this->naviHref = $naviHref;
}
这发生在一个php文件中
但在执行此步骤之前,请将$\u SERVER['PHP\u SELF']
的值分配给一个变量。像这样:
$naviHref = htmlentities($_SERVER['PHP_SELF']);
$calendar = new Calendar($naviHref);
然后,通过将变量作为参数传递给日历类型的对象,创建日历类型的对象。像这样:
$naviHref = htmlentities($_SERVER['PHP_SELF']);
$calendar = new Calendar($naviHref);
因此,最终您的php页面中将包含以下代码:
$naviHref = htmlentities($_SERVER['PHP_SELF']);
$calendar = new Calendar($naviHref);
echo $calendar->show();
之后,转到日历
构造函数并按如下方式更改它:
$calendar = new Calendar();
public function __construct($naviHref) {
$this->naviHref = $naviHref;
}
通过这种方式,您将变量$naviHref注入到类的对象
Calendar
这有点宽泛!你能不能不把重点放在你认为问题可能存在的地方,只是为了省去我们所有人都必须对所有这些代码进行台架测试我把重点放在:)对不起,但我不明白我该怎么做,因为我是PHP语言的新手。你能再解释一下吗?@Sergiu,你能给我们一些关于你在其中创建对象的文件的更多信息吗?你在那个页面上有javascript吗?或者是HTML表单,或者类似的东西?请通过重新编辑您的问题,而不是在评论中发布。这样我们大家都可以看到它们。@在创建日历的行中插入一些代码将非常有用。或者整页,如果你不介意的话?我有一张表格在下面。这会影响日历吗?@SergiuTritean抱歉,但我们需要更多:-)