您可以將鏈接(S)的父元素使用JavaScript onclick
事件:
.exterior {
display: block;
width:100px;
height:100px;
border: 1px black solid;
}
<div onclick="document.location.href='https://example.com';return true;" class="exterior">
<a href="https://stackoverflow.com">interior</a>
</div>
我不推薦在<a>
元素中使用<a>
。在<a>
中使用<a>
無效。您可以檢查W3C validator以下文件:
<!DOCTYPE html>
<html>
<head>
<title>test link in link</title>
</head>
<body>
<a href="#" class="test1">
<a href="#" class="test2">test</a>
</a>
</body>
</html>
您還可以使用兩種不同的<a>
元素(不使用JavaScript - 只有CSS的解決方案):
div {
position:relative;
border:1px solid red;
height:200px;
width:200px;
}
div a.ext {
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
z-index:0;
}
div a.int {
position:relative;
z-index:999;
}
<div>
<a class="ext" href="https://example.com"></a>
<a class="int" href="https://stackoverflow.com">test</a>
</div>
爲什麼你要把裏面的鏈接的鏈接?當然,這不是一個好主意。你如何期待它的工作? – error404
@AnululHasan好吧,如果你點擊內部鏈接,它會把你帶到那個鏈接,如果你點擊其他任何地方,它會把你帶到別的地方。 –
這個問題沒有javascript標記。你想要一個JavaScript解決方案嗎? – Danield