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

时间:2018-02-02 12:19:39

标签: javascript php css hide visibility

单击时不会显示德语,并显示英语。如果单击英语,将显示德语。我调查过hide,show,visibile部分。我甚至写了一个JavaScript脚本,但它没有用。目前,德语和英语似乎位于网站的一侧,但我只想点击德语和德语,德语页面将是英语。

<?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 个答案:

答案 0 :(得分:0)

仅限PHP(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

&#13;
&#13;
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");
&#13;
<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>
&#13;
&#13;
&#13;