0

私はjQueryアコーディオンを使用しています-ここに私のコード:

$(document).ready(function() {
    $('ul#accordion a.heading').click(function() {
        $(this).css('outline','none');
        if($(this).parent().hasClass('current')) {
            $(this).siblings('ul').slideUp('slow',function() {
                $(this).parent().removeClass('current');
                $.scrollTo('#accordion',1000);
            });
        } else {
            $('ul#accordion li.current ul').slideUp('slow',function() {
                $(this).parent().removeClass('current');
            });
            $(this).siblings('ul').slideToggle('slow',function() {
                $(this).parent().toggleClass('current');
            });
            $.scrollTo('#accordion',1000);
        }
        return false;
    });
});

問題は、ページの読み込み時に 1 li を開きたいことです。しかし、それはすべて開いています。そして、ここに私のPHPコード、1つのliカテゴリと2番目のlisカテゴリ項目があります。

<ul id="accordion">     
    <?php
        $cates=mysql_query('select * from categories order by id desc limit 10');
        while($gets=mysql_fetch_array($cates)) {
            $title=$gets['title'];
            $id=$gets['id'];
    ?>
    <li class="account">
    <?php 
    echo '<a style="text-decoration:none; color:orange;" href="#'.$title.'" class="heading account nav-user">'.$title.'</a>
    <ul id="'.$title.'">';
        $ads=mysql_query('select * from items where cid="'.$id.'" order by id desc limit 4');
        while($items=mysql_fetch_array($ads)){
            $item=$items['product_name'];
            $adid=$items['id'];
            $stringq = strip_tags($item);
            if (strlen($stringq) > 23) {
                $stringCutq = substr($stringq, 0,25);
                $stringq = substr($stringCutq, 0, strrpos($stringCutq, ' ')).'....'; 
            }
            echo '<li  class="submenu"><a style="text-decoration:none;color:grey;" href="addetail.php?id='.$adid.'">'.$stringq.'</a></li>';
        }
        echo '</ul>';
        echo '</li>';
    }
?>
</ul>

また、誰かが最高のアコーディオン jQuery を持っている場合は、本当に感謝しています。このスクリプトには jQuery ui.js ファイルが含まれていることを忘れていました。私の問題がここで解決されることを願っています。

4

0 に答える 0