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 对于这个复杂问题的解释说明
  • ¥50 三种调度算法报错 采用的你的方案
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败