dongxiangqian1855 2015-02-04 10:45
浏览 88

页面中的javascript自动文件列表

is there anyway for example when i navigate to http://example.com/links/pages/index.html

i have 4 .html files in /pages directory with names page1.html , page2.html , page3.html , page4.html

then that index.html must show me a list of pages that is exist in this /pages directory? without i list them on index.html manually by myself. i only want them to be listed at index.html when ever i create a new page at /pages directory

here's some example hope it helps : http://plnkr.co/edit/kIiod2DR6zgSpmuUNsUi?p=preview

or this example

<!-- This is index.html page in this directory http://example.com/links/pages/index.html -->

<html>
  <head>

  </head>

  <body>

    <!-- here must be listed pages that is exist in this directory /pages -->

    <!-- example for to be listed -->
    <ul>
      <li><a href="page1.html">page 1</a></li>
      <li><a href="page2.html">page 2</a></li>
      <li><a href="page3.html">page 3</a></li>
      <li><a href="page4.html">page 4</a></li>
    </ul>

  </body>

</html>
  • 写回答

1条回答 默认 最新

  • doubingling4706 2015-02-04 11:25
    关注

    Here is an example:
    in folder "pages" you have:

    • page1.html
    • page2.html
    • page3.html

    index.php in root directory will be:

    <html>
      <head>
    
      </head>
    
      <body>
    
        <!-- here must be listed pages that is exist in this directory /pages -->
    
        <?php
            $dir = 'pages';
            $pages = array_values(array_diff(scandir($dir), array('..', '.')));
        ?>
    
        <ul>
            <?php
                foreach ($pages as $page) {
                    $name = str_replace('.html', '', $page);
                    echo "<li><a href=\"$page\">$name</a></li>";
                }
            ?>
        </ul>
    
      </body>
    
    </html>
    

    the output will be:

    <html>
      <head>
    
      </head>
    
      <body>
    
        <ul>
           <li><a href="page1.html">page1</a></li>
           <li><a href="page2.html">page2</a></li>
           <li><a href="page3.html">page3</a></li>
        </ul>
    
      </body>
    
    </html>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度