2011-08-29 29 views
1

我在帖子中更改图像大小有问题(点击按钮网格/列表后)。带图像大小的网格/列表视图

这些按钮应该(后点击)变化$值为true或false(即规模图像):

<div class="products_look"> 
     <input type="button" class="view_list" onclick="" value="List" /> 
     <input type="button" class="view_grid" onclick="" value="Grid" /> 
</div> 

,这是生成的帖子网格或列表视图中的PHP函数:

<?php 
    if($value == true) { 
     echo image_products_grid(); 
    } 
    else { 
     echo image_products_list(); 
    } 
?> 

我需要在onClick标签中插入什么,点击按钮后返回php $ value(true或false)?

回答

1

为什么不在URL中使用参数?事情是这样的:

<div class="products_look"> 
    <input type="button" class="view_list" onclick="window.location = 'display.php?type=LIST'" value="List" /> 
    <input type="button" class="view_grid" onclick="window.location = 'display.php?type=GRID'" value="Grid" /> 
</div> 

然后你的PHP页面上:

<?php 
    if($_GET["type"] == "GRID") { 
     echo image_products_grid(); 
    } 
    else { 
     echo image_products_list(); 
    } 
?> 

这是解决方案,您正在寻找的类型?这不是非常优雅,但你的问题有点不清楚,所以我希望这有助于。

+0

我不认为这很容易。 它可以完成没有页面刷新?因为这些html标签'a'被分配了JS功能(即改变了css)。 – Issus

+0

我有点不确定你在问什么...你问这是否可以在没有页面刷新的情况下完成?如果是这样,我知道你唯一的方法就是使用AJAX,而不用重新加载整个页面就可以从服务器获得响应。这里有一个很好的简单例子:http://www.w3schools.com/php/php_ajax_php.asp –