dongrong1856 2017-04-05 15:57
浏览 55
已采纳

如何更新下拉菜单中每天更改的网址引用?

Every day, you download a txt file that contains the url and then I have to manually update the index.html file of a pulldown menu. Is there a way to automatically update the url without having to edit the index file? This is an example of how and dialed the file.txt that drain each day and that below a portion of the index file code.

Text1, Text2, and Text3 to remain unchanged, while the url change daily

File_url.txt

<a href='http://example.com/update1/day1.txt'>text1</a><br/>
<a href='http://example.com/update2/day1.txt'>text2</a><br/> 
<a href='http://example.com/update3/day1.txt'>text3</a><br/>

in the index file, the url are inserted so

File index.html

    <!DOCTYPE html PUBLIC>



<head>

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<title>CSS DropDown Menu</title>

<link rel="stylesheet" type="text/css" href="css/reset.css" media="screen" />

<link rel="stylesheet" type="text/css" href="css/simple.css" media="screen" />

</head>

<body>



<div id="drop-menu">

<ul id="menu">

  <li><a href="http://example.com/home.php"target="principale" >Home</a></li>

<ul>

</ul>

 </li>

 <li><a href="#"target="principale" >Extra</a>

<ul>
<li><a href='http://example.com/update1/day1.txt'target="principale">text1</a><br/></li>
<li><a href='http://example.com/update2/day1.txt'target="principale">text2</a><br/></li>
<li><a href='http://example.com/update3/day1.txt'target="principale">text3</a><br/></li>

</ul>

 </li>

 <li><a href="#">About</a></li>

 <li><a href="#">Contact</a></li>

</ul>

</div>

<iframe name="principale" src="http://example.com/home.php" marginheight="50" height="800" width="100%" allowfullscreen = "true" ></iframe>

</body>

</html>

For example, the next day I can find

File_url.txt

<a href='http://example.com/update1/day2.txt'>text1</a><br/>
<a href='http://example.com/update2/day2.txt'>text2</a><br/> 
<a href='http://example.com/update3/day2.txt'>text3</a><br/>

Is there a way to automatically update the reference Url perhaps using Text1, Text2, and Text3 that never change?

  • 写回答

2条回答 默认 最新

  • dongma0722 2017-04-05 16:47
    关注

    If you use server side script like PHP for example, you can use function like readfile() function to read the entire file then use foreach function to iterate over it's rows and render the items to your html.

    But, if you don't use server side script at once, I think you can expose the txt file so it can be accessed via URL, for example localhost/file_url.txt then use javascript ajax function to get it's content from URL and render them into your HTML.

    Here's the code using javascript to get the content of you file:

    <!DOCTYPE html PUBLIC>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>CSS DropDown Menu</title>
        <link rel="stylesheet" type="text/css" href="css/reset.css" media="screen" />
        <link rel="stylesheet" type="text/css" href="css/simple.css" media="screen" />
    </head>
    <body>
        <div id="drop-menu">
            <ul id="menu">
              <li><a href="http://example.com/home.php"target="principale" >Home</a></li>
              <li><a href="#"target="principale" >Extra</a></li>
            <ul>
            <ul id="dynamic-menu">
    
            </ul>
        </div>
        <iframe name="principale" src="http://example.com/home.php" marginheight="50" height="800" width="100%" allowfullscreen = "true" ></iframe>
    
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script>
            $(document).ready(function() {
                var menuRequest = $.ajax({
                    url: 'http://localhost:30001/file_url.txt'
                });
    
                menuRequest.done(function(data, status, xhr) {
                    var dynamicMenuWrapper = $('#dynamic-menu');
                    dynamicMenuWrapper.html(data);
                });
            });
    
        </script>
    </body>
    </html>
    

    *note: remember to make your txt file accessible by pointing it to a specific URL

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程