dqwh0109 2018-02-02 12:19
浏览 110
已采纳

当在php中点击脚本时,Elemente将使其不可见

German will not appear when clicked and will show english. If English is clicked, German will appear. I've investigated hide, show, visibile parts. I even wrote a JavaScript script, but it did not work. At the moment, German and English appear to be on the side of the site, but I want only German and German will be clicked and the German page will be English.

<?php
 session_start();
 if($_GET['lang']) {
  $_SESSION['lang'] = $_GET['lang'];
header("Location:index.php"); 
   }
  if ($_SESSION['lang'] == "en") {
$lang= "en";
 }
  elseif ($_SESSION['lang'] == "gr") {
  $lang= "gr";
 }
else {
  $lang= substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2);
 }
include 'languages/'.$lang.'.php';
  ?>

<a href="?lang=gr" style="text-decoration:none;" title="German">
<strong>German</strong> </a>
<a href="?lang=en" style="text-decoration:none;" title="English"><strong>English</strong></a>
  • 写回答

1条回答 默认 最新

  • donglian3061 2018-02-02 13:08
    关注

    PHP only (index.php)

    <html>
        <body>
            <h1>My page</h1>
            <?php
                if(isset($_GET["lang"])){
                    if($_GET["lang"] == "gr"){
                        echo '<a href="index.php?lang=en" style="text-decoration:none;" title="English"><strong>English</strong></a>';
                        /* include('gr_content.php'); */
                    } else if($_GET["lang"] == "en"){
                        echo '<a href="index.php?lang=gr" style="text-decoration:none;" title="German"><strong>German</strong></a>';
                        /* include('en_content.php'); */
                    } else {
                        echo 'no lang';
                    }
                } else {
                    echo '<a href="index.php?lang=en" style="text-decoration:none;" title="English"><strong>English</strong></a>';/* include("gr_content.php);*/
    
                }
            ?>
        </body></html>
    

    JS only

    var dict = {
                    "gr" : {"div1" : "german content 1", "div2" : "german content 2"},
                    "eng" : {"div1" : "eng content 1", "div2" : "eng content 2"}
                };
                
                function displayer(lang){
                    Object.keys(dict[lang]).forEach(function(k) {
                        document.getElementById(k).innerHTML = dict[lang][k];
                    });
                }
                
                function grClick(){
                    document.getElementById("gr").style.display = 'none';
                    document.getElementById("eng").style.display = 'block';
                    displayer("gr");
                }
                
                function engClick(){
                    document.getElementById("gr").style.display = 'block';
                    document.getElementById("eng").style.display = 'none';
                    displayer("eng");
                }
                
                displayer("gr");
    <html>
        <body>
            <h1>My page</h1>
            <a id="gr" href="#" style="text-decoration:none;display:none;" title="German" onclick="grClick()"><strong>German</strong></a>
            <a id="eng" href="#" style="text-decoration:none;" title="English" onclick="engClick()"><strong>English</strong></a>
            <div id="div1"></div><br>
            <div id="div2"></div>    
            </body>
    </html>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100