dsqve08622 2017-04-26 13:07
浏览 44
已采纳

在PHP中创建无限的嵌套列表

I know, the headline is not very specific, but I dont't know how to title it.
I want to create a list from 1 to 10. All those numbers should be clickable and open a sublist. Again with the numbers from 1-10. Like this:

  • 1
  • 2
    • 1
    • 2
    • 3

and so on... Here is some code, I've got:

<?php
$num = $_GET['zahl'];
$zahlen = array();
while($num != 0){
  $part = $num % 10;
  array_push($zahlen, $part);
  $num = floor($num/10);
}
foreach ($zahlen as $key => $value) {
$runs = $value + 1;
for ($i=1; $i < $runs ; $i++) {
  if ($i == 1) {
    echo $ulon . "
";
  }
  echo $lion . "
";
  echo $a . "ordner.php?zahl=" . $i . $amiddle . $i . $aoff . "
";
  echo $lioff . "
";
}
for ($i=1; $i < 11 ; $i++) {
  if ($i == 1) {
    echo $ulon;
  }
  echo $lion . "
";
  echo $a . "ordner.php?zahl=" . $zahlen[0] . $i . $amiddle . $i . $aoff;
  echo $lioff . "
";
}
echo $uloff;
echo "
" . "</body>";
?>
  • 写回答

2条回答 默认 最新

  • doubang9906 2017-04-26 14:05
    关注

    What you wish to achieve should be fairly straigtforward with Javascript rather than PHP - the following uses PHP only to generate the initial list and subsequent sub-lists are generated using javascript.

    <?php
        echo "<ul id='infinite-menu'>";
        for( $i=1; $i < 11; $i++ ){
            echo "<li>$i</li>";
        }
        echo "</ul>";
    ?>
    
    
    <script>
    
        var children=10;
    
        function newnodes(e){
            if( e.target.childNodes.length==1 ){
                var ul=document.createElement('ul');
                e.target.appendChild(ul);
    
                for( i=1; i < children+1; i++ ){
                    var li=document.createElement('li');
                    li.innerHTML=i;
                    ul.appendChild( li );
                }
            }
        }
        var col=document.querySelectorAll('ul#infinite-menu li');
        if( col )for( n in col )if( col[n].nodeType==1){
            col[n].addEventListener('click',newnodes,false);
        }
    
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器