douyan1896 2014-09-24 11:59
浏览 26
已采纳

由于页面重新加载而导致活动类丢失

I have two tabs on my page

  1. Tabular
  2. Graphical

My page showing two forms of same data as mentioned above, by default it is showing graphical form.

My code for tabs are:

<form method="get">
     <ul class="nav nav-tabs" role="tablist">
          <li class="active" ><a href="todayfiletype1.php?graph=1" >Graphical View</a></li>
         <li ><a href="todayfiletype1.php?graph=2">Tabular View</a></li>
    </ul>
</form> 

When I click on one of tab I want to execute below code as per the query string I passed with hyperlink, however page gets reloaded active class does not change with change in tabs

if(isset($_GET['graph']))
{
$opt=$_GET['graph'];
}
else
$opt=1;

if($opt==1)
{
//code related to graphical tab
}
else
{
//code related to tabular tab
}

Please suggest me how can I get active class as per click..Currently it is changing but lost due to page reload.

Jquery code used to switch active class

$(document).ready(function() {
     $("li").click(function(event) {
          //event.preventDefault();
          if ($("li").hasClass('active')) {
               $("li").removeClass('active');
          }
          $(this).addClass('active');
     });
});
  • 写回答

1条回答 默认 最新

  • dongmei1828 2014-09-24 12:28
    关注

    You need to add the class to the correct element, based on the value of the $opt variable:

    <form method="get">
         <ul class="nav nav-tabs" role="tablist">
              <li<?php echo ($opt==1)?' class="active"':'';?>><a href="todayfiletype1.php?graph=1" >Graphical View</a></li>
              <li<?php echo ($opt==2)?' class="active"':'';?>><a href="todayfiletype1.php?graph=2">Tabular View</a></li>
        </ul>
    </form> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图