在同一个div中显示多个链接,可以通过以下几种方式实现:
<div>
<a href="https://www.example1.com">Link 1</a>
<a href="https://www.example2.com">Link 2</a>
<a href="https://www.example3.com">Link 3</a>
</div>
<div id="links"></div>
<script>
var linksDiv = document.getElementById("links");
var link1 = document.createElement("a");
link1.href = "https://www.example1.com";
link1.textContent = "Link 1";
linksDiv.appendChild(link1);
var link2 = document.createElement("a");
link2.href = "https://www.example2.com";
link2.textContent = "Link 2";
linksDiv.appendChild(link2);
var link3 = document.createElement("a");
link3.href = "https://www.example3.com";
link3.textContent = "Link 3";
linksDiv.appendChild(link3);
</script>
<style>
.link {
display: inline-block;
margin-right: 10px;
color: blue;
text-decoration: underline;
cursor: pointer;
}
</style>
<div>
<span class="link" onclick="window.location.href='https://www.example1.com'">Link 1</span>
<span class="link" onclick="window.location.href='https://www.example2.com'">Link 2</span>
<span class="link" onclick="window.location.href='https://www.example3.com'">Link 3</span>
</div>
以上是几种常见的在同一个div中显示多个链接的方法。根据具体需求和使用场景,选择适合的方式来实现多个链接的显示效果。
领取专属 10元无门槛券
手把手带您无忧上云