【发布时间】:2011-10-31 11:40:41
【问题描述】:
问题是关于如何使用 javascript/jquery 在网页中处理 php 变量。以下代码代表场景。
用于分页的 PHP 代码片段 -
if($current_page>1)
$previous = $current_page - 1;
else
$previous = $current_page;
if($current_page==$num_pages)
$next = $current_page;
else
$next = $current_page + 1;
//the line below is for right arrow link - go to next page
<?php echo '<a href="gallery.php?p=' .$next. '">
<img src="Arrow-Right.png" width="16" height="16" title="Next Page" /> </a>';
?>
//the line below is for left arrow link - go to previous page
<?php echo '<a href="gallery.php?p=' .$previous. '">
<img src="Arrow-Left.png" width="16" height="16" title="Previous Page" /> </a>';
?>
现在我的问题 -
我想根据条件禁用左右箭头链接 -
if $current_page = $num_pages(意思是,如果达到最大页面),然后使用javascript禁用右箭头链接
if $current_page = 1(意思是,如果达到最小页面),然后使用javascript禁用左箭头链接
非常简单的分页场景,但我关心的是如何正确使用变量,因为$current_page, $num_pages 等都是 PHP 变量,我假设它们不能在任何 Javascript 代码中轻松访问。那么我如何访问它们,以便我可以使用 JS 进一步处理链接启用/禁用或使用 js 等的 css 样式...
感谢以上任何指示。
【问题讨论】:
标签: php javascript variables scope pagination