dqwh0109 2018-02-02 04: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 05: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>
    

    展开全部

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部