我只是想问为什么当我使用jsfiddle使用slidetoggle构建一个ul结构化的档案时,year> month>将其命名为WORKS,但是当我将其应用于我的档案部分时,只有年份和月份有效,标题不会显示,css对此有问题吗?

   <?php
include("connection/connect.php");

$sql2 = mysqli_query($con, "SELECT DISTINCT YEAR(post_date) FROM posts ORDER BY YEAR(post_date) DESC");
                echo "<div id='nav'><ul>";

                while($row2 = mysqli_fetch_assoc($sql2)){
                    foreach ($row2 as $year) {
                    echo "<li class='current'><b>$year</b><ul>"; //year
                        $sql3 = mysqli_query($con, "SELECT DISTINCT MONTH(post_date) FROM posts WHERE YEAR(post_date)='$year' ORDER by MONTH(post_date) DESC");

                        while($row3 = mysqli_fetch_assoc($sql3)){
                            foreach ($row3 as $month) {

                                echo "<li><a style='text-transform: none; color:#333; font-size: 14px;'>".date('F', mktime(0, 0, 0, $month, 1, 2000))."</a><ul>"; //month

                                $sql4 = mysqli_query($con, "SELECT * FROM posts WHERE MONTH(post_date)='$month' AND YEAR(post_date)='$year' ORDER by post_date DESC");
                                while($row4 = mysqli_fetch_assoc($sql4)){
                                    $title2 = $row4['post_title'];
                                    echo "<ul><li><a style='text-transform: none; color:#333; font-size: 12px;' href='pages.php?id={$row4['post_id']}'>".$title2."</a></li></ul>";//title
                                }
                            }
                            echo "</ul></li>"; //end month
                        }
                    echo "</ul></li>"; //end year
                    }
                }
                echo "</ul></div>";

    }
    ?>


在jsfiddle中,这是它的样子
2014年
 一月
 二月
 三月<  标题1
  标题2

在我的档案部分,它是这样的
2014年
 一月
 二月
 三月<
顺便说一下,这里是脚本的代码:

$(document).ready(function() {
    $("#nav ul li:not(:has(li.current))").find("ul").hide().end() // Hide all other ULs
    .click(function() {
        if (event.target==this) {
        $(this).children('ul').slideToggle('fast');
            return false;
        }
    });
});


希望您能对此有所帮助,在此先感谢您。

您可以检查我的小提琴,Jquery Slidetoggle

最佳答案

最后,我得到了答案。。我在标题附近添加了一个多余的标签,这就是为什么在删除它后不显示它的原因,现在我的档案非常好。

<?php
            include("connection/connect.php");

            $select_posts = "SELECT post_id,post_date,post_title, YEAR(post_date) AS YEAR, MONTH(post_date) AS MONTH, COUNT(*) AS postCount FROM posts";

            $run_posts = mysqli_query($con, $select_posts);

            while ($row = mysqli_fetch_array($run_posts)){

            $sql2 = mysqli_query($con, "SELECT DISTINCT YEAR(post_date) FROM posts ORDER BY YEAR(post_date) DESC");
            echo "<div id='nav'><ul>";

            while($row2 = mysqli_fetch_assoc($sql2)){
                foreach ($row2 as $year) {
                echo "<li class='current'><b>$year</b><ul>"; //year
                    $sql3 = mysqli_query($con, "SELECT DISTINCT MONTH(post_date) FROM posts WHERE YEAR(post_date)='$year' ORDER by MONTH(post_date) DESC");

                    while($row3 = mysqli_fetch_assoc($sql3)){
                        foreach ($row3 as $month) {

                            echo "<li><a style='text-transform: none; color:#333; font-size: 14px;'>".date('F', mktime(0, 0, 0, $month, 1, 2000))."</a><ul>"; //month

                            $sql4 = mysqli_query($con, "SELECT * FROM posts WHERE MONTH(post_date)='$month' AND YEAR(post_date)='$year' ORDER by post_date DESC");
                            while($row4 = mysqli_fetch_assoc($sql4)){
                                $title2 = $row4['post_title'];
                                echo "<li><a style='text-transform: none; color:#333; font-size: 12px;' href='pages.php?id={$row4['post_id']}'>".$title2."</a></li>";//title
                            }
                        }
                        echo "</ul></li>"; //end month
                    }
                echo "</ul></li>"; //end year
                }
            }
            echo "</ul></div>";

}
?>


无论如何,感谢那些试图忍受我的问题的人。

关于javascript - slidetoggle jQuery不会显示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26311225/

10-09 14:27