在Get ['status']上显示隐藏Div依赖

时间:2012-04-17 15:06:09

标签: php jquery jquery-animate

希望有人会知道如何做到这一点...... 我希望显示/隐藏工作取决于点击的图像/图标。

例如,如果单击“请求图标”,则颜色框弹出窗口将显示“请求”和Offered div。 如果单击“接受的图标”,则颜色框弹出窗口将显示“已接受”和Offered Div,但会隐藏Request div。

以下是PHP中的一些内容:

      <div <?php if($_GET['status']=="Requested"){ echo "class=iconActive";}else {echo "class=iconInactive";}?>>
        <a href="/index.php/agent-appointment-request-list/?status=Requested">
        <img src="components/com_agent/images/requestedIcon_s1.png" id="requestedIcon" alt="" /></a>
        <div class="iconTitle">Requested</div>
        </div>

这是我拥有的show / hide的jquery:

 $(".slidingDivReq").show();
 $("#show_hideReq").show();

 $('#show_hideReq').click(function(){
     $(".slidingDivReq").slideToggle();
 });

更新:这是将要显示/隐藏的内容部分。 :

<div class="AppointmentTitleFirst">
    <img src="components/com_agent/images/req_appt_title_s1.png" class="ApptIcon"></img>
    <h1>Requested Appointment # <?php echo $this->appointment->id;?>         Status:<?php echo $this->appointment->status_name;?></h1>
    <img src="components/com_agent/images/dropdown_arrow_s1.png" class="ApptDropDownArrow1" id="show_hideReq"></img>
    </div>
    <div class="clearFloat"></div>
    <div id="requestedAppointmentContent" class="slidingDivReq">
 Content here....
 </div>

差不多,我不确定如何使用GET['status']并将其与show / hide一起使用。因此,如果GET['status'] == Requested,则show_hideReq将为.show(),但我在颜色框中的其他div将使用.hide();(除非它是一个需要其他几个div的页面) .show()

希望有人知道。

2 个答案:

答案 0 :(得分:3)

  

我不确定如何使用GET ['status']并将其用于   显示/隐藏

您可以使用隐藏元素作为变量,以便在jquery中测试GET['status']。在php页面中添加此元素:

<input type="hidden" id="StatusId" value="<?php echo GET['status']; ?>"/>

然后你可以这样做:

$('#div').click(function(){
   var statusId = $("#StatusId").val();
   If( statusId  === 0){
       //Do something
   }else{
       // Do something elese
   }
});

在重定向到这个php页面的网址中发送status值,例如从js文件中看起来像:

 var url = "http://localhost/yourcurrentphpfile.php?Status=" + somevalue;
 window.location.href = url;

或重定向到此页面的php页面中点击的<a>标记应该href属性看起来像http://localhost/yourcurrentphpfile.php?Status=somevalue

yourcurrentphpfile.php是包含隐藏输入的php页面。

答案 1 :(得分:1)

您最好使用$(element).css("dissplay","none");隐藏元素,$(element).css("dissplay","inherit");来隐藏元素。

同样在PHP中,您最好使用if (isset($_GET['status']) && !empty($_GET['status']))来确保您拥有值。此外,您需要将ECHO指令编辑为:

echo 'class = "iconActive"';

echo 'class = "iconInactive"';

遵循代码的逻辑,

$(function(){ //on page load
     $("div.classActive").load(function(){
         //Do whatever you want when the div is active such as show/hide elements
     })
     $("div.classInactive").load(function(){
         //Do whatever you want when the div is inactive such as show/hide elements
     })
})

只有2个将被执行,因为页面呈现时只存在其中一个。

相关问题