简体   繁体   English

(HTML) 在中央文件中存储链接

[英](HTML) storing links in an central file

i wanna do a html but i don't know how to store links in an extra file.我想做一个 html,但我不知道如何将链接存储在一个额外的文件中。 The code is:代码是:

<a title="DESCR" href="LINK" target="_blank" style="color: white">NAME</a>

i want to get the LINK in an central File.我想在中央文件中获取 LINK。 Optional if its possible, the Name too.如果可能,名称也是可选的。 i tried for the last 2 Days and found nothing that works.我尝试了过去 2 天,但没有发现任何有效的方法。 i tried to create an css for this but css is only for design purposes...我试图为此创建一个 css,但 css 仅用于设计目的...

does anyone have an idea how to do it?有没有人知道怎么做?

You can define your data in javascript and use a little script that will use the data to create the link-elements for you.您可以在 javascript 中定义数据并使用一个小脚本,该脚本将使用数据为您创建链接元素。

Here the linksData is an array of urls.这里的linksData是一个 url 数组。 You can add more infos when you use an array of objects (json).当您使用对象数组 (json) 时,您可以添加更多信息。 The script goes through that array and creates a new anchor for each url.该脚本遍历该数组并为每个 url 创建一个新的锚点。

 var linksData = ["https://example.com", "https://stackoverflow.com"]; var linksList = document.getElementById("links"); for (var i = 0; i < linksData.length; ++i) { var listItem = document.createElement("li"); var anchor = document.createElement("a"); anchor.setAttribute("href", linksData[i]); var text = document.createTextNode(linksData[i]); anchor.appendChild(text); listItem.appendChild(anchor); linksList.appendChild(listItem); }
 <ul id="links"> </ul>

To include an external javascript in your html you will tyically add要在您的 html 中包含外部 javascript,您将 tyically 添加

 <script src="myScript.js"></script>

to the head section of your html.到您的 html 的head部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM