简体   繁体   English

如何使用PHP或HTML但不使用JS创建简单的树菜单?

[英]How to create simple tree menu using PHP or HTML but without JS?

I want to create simple tree menu. 我想创建简单的树菜单。 But I can only use PHP or HTML. 但是我只能使用PHP或HTML。 In my case I am not allowed to include any JavaScripts. 就我而言,不允许包含任何JavaScript。

CSS Play的Stu Nichols将是一个不错的起点。

IMHO, it's bad form. 恕我直言,这是错误的形式。 But you could use the GET method with links to pass values to your PHP file then return the appropriate response to the page. 但是您可以使用带有链接的GET方法将值传递到PHP文件,然后将适当的响应返回给页面。

ie. 即。

<?php
    if(!isset($_GET['link'])){
        $_GET['link'] = ""; // if not set, gets dummy value
    }

    $link = $_GET['link'];

    function showPage($link){
        switch($link){
            case "home":
                echo "<a href='page.php?link=homesub1'>Home Sub Menu 1</a><br>";
                echo "<a href='page.php?link=homesub2'>Home Sub Menu 2</a>";
                break;
            case "other":
                echo "<a href='page.php?link=osub1'>Other Page Sub Menu 1</a><br>";
                echo "<a href='page.php?link=osub2'>Other Page Sub Menu 2</a>";
                break;
        }
    }
?>
<a href="page.php?link=home">HOME</a>
<a href="page.php?link=other">Some Page</a>

<br>
<?php
    if($link != ""){
        showPage($link);
    }
?>

Obviously, a lot of thought has to be put in for the design to work. 显然,要使设计生效,必须考虑很多问题。 It's a disaster but it gets the job done. 这是一场灾难,但它完成了工作。

Note: A better approach to this would be to convince whoever is in-charge to let you use JS/jQuery. 注意:一种更好的方法是说服谁负责让您使用JS / jQuery。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM