【问题标题】:Add class when redirecting from specific page从特定页面重定向时添加类
【发布时间】:2018-03-15 13:27:44
【问题描述】:

是否可以在页面加载时将类添加到 div,但仅在从特定链接/页面重定向时?

我的登录页面上有一个<a href="marketing.php" id="openMyMaterialTab"><button class="secondaryAction">See all</button></a> 链接,它应该在marketing.php 上的一个div 中添加一个类以进行重定向。当页面从其他链接加载时,此类不应处于活动状态。

为澄清而编辑

【问题讨论】:

  • 我问是因为我不知道。不过,我已经测试了一些在谷歌上找到的例子,但没有运气。

标签: php jquery html url redirect


【解决方案1】:

尝试将此添加到您的引导页面

session_start();
// page and classes 
$classes = array(
                    'page1.php' => 'class1',
                    'page2.php' => 'class2',
                    'index.php' => 'class3',
            );


$_SESSION['classes'] = $classes;

在每个特定页面上

$predefined_classes = $_SESSION['classes'];
$class = "";

if( isset( $predefined_classes[ basename(__FILE__) ] ) ){

    $class = $predefined_classes[ basename(__FILE__) ];
}

现在使用这个 $class,就像。

<button class="<?php echo $class; ?>"> </button>

【讨论】:

  • @CarstenAndersen 你不需要在 PHP 中使用 bootstrap
  • 你的两个类都应该根据页面变化吗
猜你喜欢
  • 1970-01-01
  • 2013-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-09
  • 1970-01-01
  • 1970-01-01
  • 2010-12-06
相关资源
最近更新 更多