我是 PHP 的超级初学者,所以我仍在努力掌握它。我想要这种情况:如果每个a都被点击,背景色填充,以便用户可以知道点击了什么。为此,我通常使用 jQuery,并且每次都有效。"index.php?lang=en"但是,自从我输入href以来它一直没有用,但是当我改为"index.php?lang=en"“#”时,它可以工作但语言没有改变。请检查我的代码,让我知道问题所在。索引.php<?php include "config.php";?> <header> <div class="header-con"> <nav class="lang"> <a href="index.php?lang=en" class="lang_a">en</a> <a href="index.php?lang=ko" class="lang_a">ko</a> </nav> </div> </header>jQuery (function($){ $(function(){ var $header = $('header'), $lang_a = $header.find('.lang a'); $lang_a.on('click', function(){ $lang_a.removeClass(); $(this).addClass('on'); }); }); })(jQuery);CSS.lang a { padding: 0 6px; font-weight: normal; transition: all .3s } .lang a:hover, .lang a.on { background-color: #191970; color: #eee }配置文件<?phpsession_start();if (!isset($_SESSION['lang'])) $_SESSION['lang'] = "en";else if (isset($_GET['lang']) && $_SESSION['lang'] != $_GET['lang'] && !empty($_GET['lang'])) { if ($_GET['lang'] == "en") $_SESSION['lang'] = "en"; else if ($_GET['lang'] == "ko") $_SESSION['lang'] = "ko";}require_once "languages/".$_SESSION['lang'].".php"; ?>这里是语言文件。en.php<?php $lang = array( "sin" => "A", "sin_title" => "B", "sin_con" => "C" );?>ko.php<?php $lang = array( "sin" => "가", "sin_title" => "나", "sin_con" => "다" );?>
1 回答
缥缈止盈
TA贡献2041条经验 获得超4个赞
您想更新链接的类名(“a”元素)对吗?
您可以通过获取当前会话并执行以下操作来做到这一点:D
<?php include "config.php"; ?>
<header>
<div class="header-con">
<nav class="lang">
<a href="index.php?lang=en" class="lang_a <?php echo $_SESSION['lang']==='en' ? 'on' : ''; ?>">en</a>
<a href="index.php?lang=ko" class="lang_a <?php echo $_SESSION['lang']==='ko' ? 'on' : ''; ?>">ko</a>
</nav>
</div>
</header>
- 1 回答
- 0 关注
- 96 浏览
添加回答
举报
0/150
提交
取消