如何从另一个文件中提取动态 href link

How to extract a dynamic href link from another file

如何在我的网页上创建一个动态 href,它可以从另一个文件读取链接,这样每次我上传一个包含不同链接集的新文件时,href 路径都会改变?

文本文件包含以下记录:
1 www.google.com
2 www.apple.com
3 www.ibm.com

HTML 页

<div class="slide" id="slide-1">
<a href="(*path of text file + 1st record*)"  target="_blank"> 
<img class="resize" src="/images/DIY00/1.jpg" alt=""/> </a></div>

<div class="slide" id="slide-2">
<a href="(*path of text file + 2nd record*)" target="_blank"> 
<img class="resize" src="/images/DIY00/2.jpg" alt=""/> </a></div>

<div class="slide" id="slide-3">
<a href="(*path of text file + 3rd record*)" target="_blank"> 
<img class="resize" src="/images/DIY00/3.jpg" alt=""/> </a></div>

很难说清您在这里问的是什么,但我认为您希望能够使用更新的 url 提取连续的 href?如果是这种情况,您应该能够将更新后的 href 作为新字符串传递,因为 href 元素最初就是这样传递的。

我想就是这样了。如果 1.txt 上的第一行是 www.google.com,解析到该域的超链接。

<script>
  var xhttp = new XMLHttpRequest(); 
  xhttp.onreadystatechange = function() { 
   if (this.readyState == 4 && this.status == 200) { 
     document.getElementById("link1").href=this.responseText;
    }
  };

xhttp.open("GET", "https://example.com/1.txt", true); 
xhttp.send(xhttp); 
</script>

<a id="link1" href="#" target="_blank"></a> </div>