slidetoggle jquery将不会显示

时间:2014-10-11 04:55:33

标签: javascript jquery html css

我只是想问为什么当我使用jsfiddle构建一个带有slidetoggle的ul li结构化档案时,年份>月份>标题它可以工作,但是当我将它应用到我的档案部分时,只有年份和月份作品,标题不会显示,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
 一月
 二月
 3月&lt;&lt;(点击并显示标题)
  标题1
  标题2

在我的档案部分,这就是它的样子 的 2014
 一月
 二月
 三月&lt;&lt;(点击了标题赢得&#39; t显示)

顺便说一句,这里是脚本的代码:

$(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

1 个答案:

答案 0 :(得分:0)

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

<?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>"; 

}
?>

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